I want to put data from the command line into app.ctx so that my workers have access to it. Using version 22.9.1 this works using 22.12 the property isn’t set when accessed in the workers.
Sample application
#!/usr/bin/env python3
from sanic import Sanic
from sanic import response as res
app = Sanic(__name__)
@app.route("/")
async def test(req):
return res.text("I\'m a teapot", status=418)
@app.before_server_start
def worker_init(app):
print("Argument is ", app.ctx.arg1)
if __name__ == '__main__':
app.ctx.arg1 = 'argument from command line'
app.run(host="0.0.0.0", port=8000)
This works in 22.9.1, however 22.12 results in the following error.
[2023-01-19 14:45:09 -0600] [68062] [ERROR] 'types.SimpleNamespace' object has no attribute 'arg1'
Traceback (most recent call last):
File "/home/jschewe/projects/sanic-bugs/pass-command-line/venv/lib/python3.10/site-packages/sanic/worker/serve.py", line 117, in worker_serve
return _serve_http_1(
File "/home/jschewe/projects/sanic-bugs/pass-command-line/venv/lib/python3.10/site-packages/sanic/server/runners.py", line 231, in _serve_http_1
loop.run_until_complete(app._server_event("init", "before"))
File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
File "/home/jschewe/projects/sanic-bugs/pass-command-line/venv/lib/python3.10/site-packages/sanic/app.py", line 1598, in _server_event
await self.dispatch(
File "/home/jschewe/projects/sanic-bugs/pass-command-line/venv/lib/python3.10/site-packages/sanic/signals.py", line 195, in dispatch
return await dispatch
File "/home/jschewe/projects/sanic-bugs/pass-command-line/venv/lib/python3.10/site-packages/sanic/signals.py", line 165, in _dispatch
retval = await maybe_coroutine
File "/home/jschewe/projects/sanic-bugs/pass-command-line/venv/lib/python3.10/site-packages/sanic/app.py", line 1177, in _listener
maybe_coro = listener(app) # type: ignore
File "/home/jschewe/projects/sanic-bugs/pass-command-line/simple_app.py", line 15, in worker_init
print("Argument is ", app.ctx.arg1)
AttributeError: 'types.SimpleNamespace' object has no attribute 'arg1'
I expect this is related to the worker manager rewrite.