gpt4 book ai didi

python - Flask APP - ValueError : signal only works in main thread

转载 作者:太空狗 更新时间:2023-10-29 17:56:37 46 4
gpt4 key购买 nike

我尝试创建一个简单的 flask 应用程序:

from flask import Flask

app = Flask(__name__)

if __name__ == '__main__':
app.run()

但是当我添加调试时:

FLASK_APP = run.py
FLASK_ENV = development
FLASK_DEBUG = 1

我收到以下错误:

ValueError: signal only works in main thread

这里是完整的堆栈跟踪

FLASK_APP = run.py
FLASK_ENV = development
FLASK_DEBUG = 1
In folder c:/MyProjectPath/api
c:\MyProjectPath\api\venv\Scripts\python.exe -m flask run
* Serving Flask-SocketIO app "run.py"
* Forcing debug mode on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 283-122-745
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\appdata\local\programs\python\python37\Lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "c:\appdata\local\programs\python\python37\Lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "c:\MyProjectPath\api\venv\lib\site-packages\flask_socketio\cli.py", line 59, in run_server
return run_command()
File "c:\MyProjectPath\api\venv\lib\site-packages\click\core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "c:\MyProjectPath\api\venv\lib\site-packages\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "c:\MyProjectPath\api\venv\lib\site-packages\click\core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\MyProjectPath\api\venv\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "c:\MyProjectPath\api\venv\lib\site-packages\click\decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "c:\MyProjectPath\api\venv\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "c:\MyProjectPath\api\venv\lib\site-packages\flask\cli.py", line 771, in run_command
threaded=with_threads, ssl_context=cert)
File "c:\MyProjectPath\api\venv\lib\site-packages\werkzeug\serving.py", line 812, in run_simple
reloader_type)
File "c:\MyProjectPath\api\venv\lib\site-packages\werkzeug\_reloader.py", line 267, in run_with_reloader
signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
File "c:\appdata\local\programs\python\python37\Lib\signal.py", line 47, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread

最佳答案

您面临的问题与替换 flask run 命令的 Flask-SocketIO 包中的错误有关。由于这个 Flask-SocketIO 总是被使用,即使你不导入它。有几种解决方案:

  1. 卸载 Flask-SocketIO
  2. 不要使用flask run,而是运行程序的主文件
  3. 禁用调试
  4. 如果需要调试则禁用自动加载 flask run --no-reload

对 Flask-SocketIO 错误的引用:issue 817

关于python - Flask APP - ValueError : signal only works in main thread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53522052/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com