-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to / doc: async configuration / awaitable loop.start() #2575
Comments
You can pretty much do that: async def main():
config = await get_config()
application = SomeApp(config)
application.listen(config["port"])
mainloop = IOLoop.current()
mainloop.spawn_callback(main)
mainloop.start() You then probably want to add a signal handler which calls |
Yeah, this is probably worth documenting as an example; I use |
This is cool, but hangs if startup code raises an exception:
This is better, as I was kinda hoping to use |
Deprecation changes in python 3.10 forced us to update all the examples to use |
User guide advocates following to start a web server:
Now let's bring in some async library and use that to get application config:
Then comes aio-libs/aiohttp#3331 where
iohttp
(kinda rightfully) decided thatasyncio.get_event_loop().is_running()
should beTrue
.Now SomeApp constructor is going to create a
aiohttp.TCPConnector(...)
(a transitive dependency), which makesaiohttp
unhappy (warning only, nothing is awaited at this point, but iohttp takes a reference to current event loop).I wish I could express application setup and start as:
I this something like this would also be useful in tests, where a server may be started and stopped for each test.
P.S. I apologise if this was covered somewhere and I couldn't find a doc or past issue.
The text was updated successfully, but these errors were encountered: