question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

npm run flask-server "ValueError: signal only works in main thread"

See original GitHub issue

when I run npm run flask-server, I got this error

> FLASK_APP=$PWD/autoapp.py FLASK_DEBUG=1 flask run

 * Serving Flask-SocketIO app "autoapp"
 * Forcing debug mode on
 * Restarting with fsevents reloader
 * Debugger is active!
 * Debugger PIN: 228-328-364
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/site-packages/flask_socketio/cli.py", line 56, in run_server
    return run_command()
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/flask/cli.py", line 438, in run_command
    use_debugger=debugger, threaded=with_threads)
  File "/usr/local/lib/python2.7/site-packages/werkzeug/serving.py", line 737, in run_simple
    reloader_type)
  File "/usr/local/lib/python2.7/site-packages/werkzeug/_reloader.py", line 257, in run_with_reloader
    signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
ValueError: signal only works in main thread

I search on google and got this: https://stackoverflow.com/questions/31264826/start-a-flask-application-in-separate-thread

It seems I can’t use debug=True and use_reloader=True both. But it’s useful reloading server when code changes in debug mode. Then I change autoapp.py like this:

# -*- coding: utf-8 -*-
"""Create an application instance."""
from flask.helpers import get_debug_flag

from myflaskapp.app import create_app
from myflaskapp.settings import DevConfig, ProdConfig

CONFIG = DevConfig if get_debug_flag() else ProdConfig
app = create_app(CONFIG)
app.run(debug=True, use_reloader=True)

and just run python autoapp.py, It works well.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

1reaction
coolbreezeqfcommented, Dec 29, 2018
 FLASK_APP=app.py FLASK_DEBUG=1 flask run
 * Serving Flask-SocketIO app "app"
...

卸载 Flask-SocketIO pip uninstall Flask-SocketIO 后,就能正常运行

 FLASK_APP=app.py FLASK_DEBUG=1 flask run
 * Serving Flask app "app"
...
0reactions
jamescurtincommented, Jun 10, 2019

Going to close this issue out, as it seems the problem was identified & the template does not currently use Flask-SocketIO. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flask APP - ValueError: signal only works in main thread
The problem you are facing has to do with a bug in the Flask-SocketIO package which replaces the flask run command.
Read more >
valueerror: signal only works in main thread flask, signal only works ...
This means that signals can't be used as a means of inter-thread communication. You can use the synchronization primitives from the threading module...
Read more >
Flask in a thread - Reddit
My question would be, how can I run Flask as a threat? I thought of something like this: ... ValueError: signal only works...
Read more >
A Template for Creating a Full Stack Web Application with ...
The aim of this article is to help you start your own full-stack web application with a Python Flask server and a React...
Read more >
记录flask框架下使用signal遇到的错误:ValueError - CSDN博客
You're running Flask in debug mode, which enables the reloader ... Flask && ROS出现ValueError: signal only works in main thread问题.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found