【发布时间】:2021-12-31 10:21:57
【问题描述】:
我正在尝试从sanic getting started example 运行服务器,这是我在server.py 中的代码:
from sanic import Sanic
from sanic.response import text
app = Sanic("MyHelloWorldApp")
@app.get("/")
async def hello_world(request):
return text("Hello, world.")
当我运行默认命令 sanic server.app 时,一切正常:
$ sanic server.app
[2021-12-31 17:08:21 +0700] [22196] [INFO]
┌─────────────────────────────────────────────────────────────┐
│ Sanic v21.12.0 │
│ Goin' Fast @ http://127.0.0.1:8000 │
├───────────────────────┬─────────────────────────────────────┤
│ │ mode: production, single worker │
│ ▄███ █████ ██ │ server: sanic │
│ ██ │ python: 3.9.4 │
│ ▀███████ ███▄ │ platform: Windows-10-10.0.19041-SP0 │
│ ██ │ packages: sanic-routing==0.7.2 │
│ ████ ████████▀ │ │
│ │ │
│ Build Fast. Run Fast. │ │
└───────────────────────┴─────────────────────────────────────┘
[2021-12-31 17:08:21 +0700] [22196] [WARNING] Sanic is running in PRODUCTION mode. Consider using '--debug' or '--dev' while actively developing your application.
[2021-12-31 17:08:21 +0700] [22196] [INFO] Starting worker [22196]
但是当我尝试在开发模式下运行时,它会抛出一个错误:
$ sanic --dev server.app
Starting in v22.3, --debug will no longer automatically run the auto-reloader.
Switch to --dev to continue using that functionality.
c:\users\ev\repos\test-dashboard\venv\scripts\python.exe: Error while finding module specification for '__main__' (ValueError: __main__.__spec__ is None)
我应该添加一些东西以在开发模式下运行 sanic 吗?
【问题讨论】: