I'm working on a Flask Application. As the server should constantly send information to a receiver, every views route call needs to call a function that controls a control queue of a parallel running process.
the whole error message:
C:\Users\fabik\PycharmProjects\LEDStripControlWebapp\venv\Scripts\python.exe C:/Users/fabik/PycharmProjects/LEDStripControlWebapp_ErrorRecreation/main.py
* Serving Flask app "website" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Program Files\Python39\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "C:\Program Files\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Program Files\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "C:\Program Files\Python39\lib\runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Program Files\Python39\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\fabik\PycharmProjects\LEDStripControlWebapp_ErrorRecreation\main.py", line 3, in <module>
app = create_app()
File "C:\Users\fabik\PycharmProjects\LEDStripControlWebapp_ErrorRecreation\website\__init__.py", line 7, in create_app
from .views import views
File "C:\Users\fabik\PycharmProjects\LEDStripControlWebapp_ErrorRecreation\website\views.py", line 8, in <module>
control.start_loop()
File "C:\Users\fabik\PycharmProjects\LEDStripControlWebapp_ErrorRecreation\control\control.py", line 10, in start_loop
self._process.start()
File "C:\Program Files\Python39\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "C:\Program Files\Python39\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Program Files\Python39\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "C:\Program Files\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Program Files\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "C:\Program Files\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
(I'm actually getting this message twice when running the main.py file)
No clue what's wrong.
main.py File:
from website import create_app
app = create_app()
if __name__ == "__main__":
app.run(debug=True)
init.py File:
from flask import Flask
def create_app():
app = Flask(__name__)
app.config["SECRET_KEY"] = "thisstringisveryrandom"
from .views import views
app.register_blueprint(views, url_prefix="/")
return app
views.py File:
from flask import Blueprint, render_template, request
from control.control import Control
views = Blueprint("views", __name__)
control = Control()
control.start_loop()
@views.route("/", methods=["GET", "POST"])
def home():
if request.method == "GET":
pass
if request.method == "POST":
pass
return render_template("base.html")
control.py File:
from multiprocessing import Queue, Process
class Control:
def __init__(self):
self._control_queue = Queue()
self._process = Process(target=self._loop)
self._process.daemon = True
def start_loop(self):
self._process.start()
@staticmethod
def _loop(control_queue, connection):
while True:
#this reacts to control_queue
pass