Sanic fails to start when the source files are frozen with cx_Freeze i.e. when only the pyc files are available
jangxx opened this issue · comments
Describe the bug
Running startup()
on the http server fails with
Traceback (most recent call last):
File "server\main.py", line 133, in async_main
File "C:\path\venv\lib\site-packages\sanic\app.py", line 1541, in _startup
File "C:\path\venv\lib\site-packages\sanic\touchup\service.py", line 24, in run
File "C:\path\venv\lib\site-packages\sanic\touchup\schemes\base.py", line 27, in build
File "C:\Program Files\Python310\lib\inspect.py", line 1147, in getsource
File "C:\Program Files\Python310\lib\inspect.py", line 1129, in getsourcelines
File "C:\Program Files\Python310\lib\inspect.py", line 958, in findsource
OSError: could not get source code
when the scripts are frozen with cx_Freeze and run on a different machine. I'm guessing this is due to the fact that Sanic tries to look in the original location of the source files which obviously doesn't exist on other machines.
Code snippet
http_server = await app.create_server(
host="localhost",
port=64152,
return_asyncio_server=True
)
await http_server.startup()
Expected behavior
The server starts.
Environment (please complete the following information):
Sanic v22.6.2
Goin' Fast @ http://localhost:64152
mode: production, single worker
server: sanic, HTTP/1.1
python: 3.10.7
platform: Windows-10-10.0.19044
packages: sanic-routing==22.3.0
Additional context
Correct, an optimization step. You should disable as shown above in this case.