-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
Support multiple background tasks in BackgroundManager #246
Comments
Seems like a sensible tack yup. One alternative that we could end up exploring at some point would be to use a different pattern style here. We're using the background manager in order to allow us to perform simultanous read/writes. The urllib3 async work instead uses a "read and write for a bit" primitive that backends need to implement. I won't get into digging into that in detail here, but it's feasible that it could be a neater pattern to have our Socket interface expose a That's almost certainly more work, since it'd mean rejigging the h2/h11 implementations a bit, but it's also more constrained than exposing full background managers as part of the concurrency interface. (Tho we've also got a related bit of work around the ASGI implementation, which'd need further thinking about.) |
Actually, we're also going to need the background manager in Essentially, this: loop = asyncio.get_event_loop()
app_task = loop.create_task(run_app())
# ...
async def on_close():
await app_task would become: background = await backend.background_manager(run_app).start() # alias to .__aenter__()
# ...
async def on_close():
await background.close() # alias to .__aexit__(None, None, None) As visible here, thanks to the refactor getting rid of But regarding the |
I'll close this for now since the ability to run multiple background tasks isn't a requirement anymore. :-) |
The
BackgroundManager
is used indispatchers/http11.py
anddispatchers/http2.py
to concurrently send the request and read the first part of the response. Its usage currently looks like this:This is limited in that we cannot start more than one task easily. However, we will need this feature to generalize the usage of
ConcurrencyBackend
across the code base.Here's a more flexible API, inspired by trio's nurseries:
Usage with multiple tasks:
The text was updated successfully, but these errors were encountered: