Hello! I want to run the Flask server in a different Process to have the main thread free to do something else. Running it with app.debug = True produces
C:\Users\Jonas\.venvs\unicorn34\Scripts\python.exe C:/Users/Jonas/Dropbox/Code/unicorn/core/server_http.py * Running on http://127.0.0.1:5000/ Exception in thread Thread-1: Traceback (most recent call last): File "C:\Python34-64\lib\threading.py", line 921, in _bootstrap_inner self.run() File "C:\Python34-64\lib\threading.py", line 869, in run self._target(*self._args, **self._kwargs) File "C:\Users\Jonas\.venvs\unicorn34\lib\site-packages\flask\app.py", line 772, in run run_simple(host, port, self, **options) File "C:\Users\Jonas\.venvs\unicorn34\lib\site-packages\werkzeug\serving.py", line 708, in run_simple run_with_reloader(inner, extra_files, reloader_interval) File "C:\Users\Jonas\.venvs\unicorn34\lib\site-packages\werkzeug\serving.py", line 609, in run_with_reloader signal.signal(signal.SIGTERM, lambda *args: sys.exit(0)) ValueError: signal only works in main thread So, I made this hack to just comment out the line to not send a SIGTERM on exit: # Dirties hack of my life def my_run_with_reloader(main_func, extra_files=None, interval=1): """Run the given function in an independent python interpreter.""" # Here, I commented out the SIGTERM signal on exit. # Has this any implications on stability or is it ok, just not good practice? # signal.signal(signal.SIGTERM, lambda *args: sys.exit(0)) if os.environ.get('WERKZEUG_RUN_MAIN') == 'true': thread.start_new_thread(main_func, ()) try: werkzeug.serving.reloader_loop(extra_files, interval) except KeyboardInterrupt: return try: sys.exit(werkzeug.serving.restart_with_reloader()) except KeyboardInterrupt: pass def start_server(): def partial(app): app.debug = settings.DEBUG app.host = '0.0.0.0' app.port = settings.HTTP_PORT return app werkzeug.serving.run_with_reloader = my_run_with_reloader Has this any implications on stability or is it ok, just not good practice? Best, Jonas Gröger -- You received this message because you are subscribed to the Google Groups "pocoo-libs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pocoo-libs. For more options, visit https://groups.google.com/groups/opt_out.
