sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.
https://sanic.dev
MIT License
18.11k stars 1.55k forks source link

启动报错 #2985

Open f754699 opened 4 months ago

f754699 commented 4 months ago

Is there an existing issue for this?

Describe the bug

 File "F:\pythonproject\sanicResolve2\.venv\Lib\site-packages\sanic\mixins\startup.py", line 1180, in serve
    while cls._get_process_states(worker_state):
                                  ^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'worker_state' where it is not associated with a value

Code snippet

from sanic import Sanic, text, json

app = Sanic("fuwu")

if __name__ == '__main__':
    app.run(host="0,0,0,0", port=8000, )

Expected Behavior

启动就报错,

How do you run Sanic?

as a model

Operating System

Windows

Sanic Version

sanic = {extras = ["ext"], version = "^24.6.0"}

Additional context

No response

ChihweiLHBird commented 4 months ago
from sanic import Sanic, text, json

app = Sanic("fuwu")

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=8000)

Setting the correct host name seems to address the issue. But we might want to implement a host name validator to avoid confusing error message.

host里的,改为.即可解决问题。同时建议在Linux或Unix系统上尝试

pygeek commented 3 months ago

This is still a bug, however. mixins.startup.serve should still exit gracefully—fixed in my PR.