每次运行代码时,我都会看到Serving Flask-SocketIO app "app.py"
我的系统上甚至没有SpcketIO
import os, passlib ,requests ,time ,json
from flask import Flask, session , render_template , request,redirect,url_for ,jsonify
from flask_session import Session
import pandas as pd
from flask_uploads import UploadSet, configure_uploads, IMAGES, patch_request_class
from werkzeug import secure_filename
from datetime import date , datetime
from flask_sqlalchemy import SQLAlchemy
from passlib.hash import sha256_crypt
from flask_login import LoginManager , UserMixin , current_user ,login_user ,login_required ,logout_user
app = Flask(__name__)
在我的代码末尾,我已经拥有
if __name__ == "__main__":
app.run(debug=True)
我通过cmd运行系统:flask run
过去我一直忽略此错误,因为其他所有内容都在起作用,但是当我尝试添加app.run(debug=True,host='0.0.0.0')
debug=True
似乎也没有做任何事情,我不得不通过CMD set Flask_Debug=1
我遇到一个错误,指出ValueError: signal only works in main thread
该应用程序根本没有运行
确切错误
* Serving Flask-SocketIO app "app.py"
* Forcing debug mode on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 885-769-473
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\threading.py
", line 917, in _bootstrap_inner
self.run()
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\threading.py
", line 865, in run
self._target(*self._args, **self._kwargs)
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\flask_socketio\cli.py", line 59, in run_server
return run_command()
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\flask\cli.py", line 771, in run_command
threaded=with_threads, ssl_context=cert)
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\werkzeug\serving.py", line 812, in run_simple
reloader_type)
File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\werkzeug\_reloader.py", line 267, in run_with_reloader
signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
File "c:\users\mena\appdata\local\programs\python\python37-32\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
要恢复工作,我必须关闭cmd set Flask_Debug=0
我的系统出了什么问题?
答案 0 :(得分:0)
请检查是否有其他线程在运行。然后尝试从终端通过命令python app.py运行您的应用程序,而不是烧瓶运行。可能是flask run命令调用了应用程序不需要的其他服务。
我还假设您正在Linux系统上工作。在终端(Windows cmd)和app.py所在的项目目录中,只需输入python(使用的python / python3依赖于哪个版本)app.py并按Enter。
在命令行上尝试
python app.py
or
python3 app.py