You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
to reuse an aiohttp client session during the whole life of a server. Or any other asyncornous context manager like a connection to a database and so on.
Expected behaviour
To easily run an aiohttp server inside an asyncronous context manager.
Obviously it can't be done with the actual run_app, and probably easily done with the _run_app, but, _.
Maybe the AppRunner could eat some code from _run_app allowing one to completly bypass _run_app with something like:
runner=AppRunner(app, ...)
awaitrunner.setup(host, path, sock, port) # Doing most of _run_app current code hereasyncwithSomething() assomething:
app["something"] =somethingawaitrunner.run_forever() # The while True of the current _run_app
Does it looks like a good idea? Should I try a PR? Or am I getting something wrong?
The text was updated successfully, but these errors were encountered:
I missed cleanup_ctx while reading the doc, thanks!
In my current case I'm having two context managers, using cleanup_ctx instead of on_startup and on_cleanup gives me 13 new lines for 18 lines removed, and I'm no longer calling __aenter__ and __aexit__ myself, so it's better, yes.
It probably miss a link somewhere, to this, to make it easier to find from maybe on_startup?
Long story short
I think I'd like to do:
to reuse an aiohttp client session during the whole life of a server. Or any other asyncornous context manager like a connection to a database and so on.
Expected behaviour
To easily run an aiohttp server inside an asyncronous context manager.
Actual behaviour
I'm actually doing:
but I'm not proud of it.
Obviously it can't be done with the actual
run_app
, and probably easily done with the_run_app
, but,_
.Maybe the
AppRunner
could eat some code from_run_app
allowing one to completly bypass_run_app
with something like:Does it looks like a good idea? Should I try a PR? Or am I getting something wrong?
The text was updated successfully, but these errors were encountered: