[ValueError: signal only works in main thread]
问题:
Traceback (most recent call last):
File "/home/python/.virtualenvs/toutiao/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/home/python/toutiao-backend/toutiao/__init__.py", line 6, in <module>
import socketio
File "/home/python/.virtualenvs/toutiao/lib/python3.6/site-packages/socketio/__init__.py", line 3, in <module>
from .client import Client
File "/home/python/.virtualenvs/toutiao/lib/python3.6/site-packages/socketio/client.py", line 5, in <module>
import engineio
File "/home/python/.virtualenvs/toutiao/lib/python3.6/site-packages/engineio/__init__.py", line 3, in <module>
from .client import Client
File "/home/python/.virtualenvs/toutiao/lib/python3.6/site-packages/engineio/client.py", line 44, in <module>
original_signal_handler = signal.signal(signal.SIGINT, signal_handler)
File "/usr/lib64/python3.6/signal.py", line 47, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
解决方法:
推测与项目中socketio有关
1.socketio 插件在使用flask run启动,出现 ValueError: signal only works in main thread 异常的问题。
如果非要flask run启动,flask run --no-reload 切记一定要带 --no-reload 参数,本人测试已经成功。
2.如果是使用app.run启动,run()指定参数use_reloader=False, 这个方法我还没进行尝试
app.run(debug=True, use_reloader=False)