Skyscanner / aiotask-context

Contextual information for asyncio tasks
MIT License
161 stars 25 forks source link

how to use with sanic mutiple worker #28

Closed striderhcx closed 4 years ago

striderhcx commented 4 years ago

I used this package to add request_id when i use logging to record the access log. But i read the document, https://sanic.readthedocs.io/en/latest/sanic/deploying.html#asynchronous-support-and-sharing-the-loop, is this mean that aiotask-context not support mutiprocess? My english is poor, hope that i describe clear enough.

when use:

asyncio.set_event_loop(uvloop.new_event_loop())
    server = app.create_server(host="0.0.0.0", port=8000, return_asyncio_server=True)
    loop = asyncio.get_event_loop()
    loop.set_task_factory(context.task_factory)
    task = asyncio.ensure_future(server)
    try:
        loop.run_forever()
    except:
        loop.stop()

can you give a example how to use sanic mutiple workers?

striderhcx commented 4 years ago

I get it:

app.register_listener(init_loop_context, "before_server_start")