-
Notifications
You must be signed in to change notification settings - Fork 34
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
Fire and forget async ctx blocks anti-pattern #70
base: main
Are you sure you want to change the base?
Conversation
9d684f2
to
0eec1f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the example code here needs to be fleshed out a bit more. Ideally using something self-contained that doesn't lean on our trinity architecture which won't be familiar to everyone.
Example in-my-opinion should include the implementation of the async context manager, showing it returning a future/task type object, and then a version of the code you posted showing how you can end up with a dead background task if you don't include awaiting it as well.
0eec1f3
to
ec0bb00
Compare
ec0bb00
to
9cdfbd5
Compare
@pipermerriam care to have another look? I've added a self-contained example but also left the reference to the trinity code where I first noticed this pattern as I think it's good to have an example from real production code |
``` | ||
|
||
In the above example, if the background task running `producer(stream_writer)` terminates without | ||
closing the the writer, the `run()` function would continue running indefinitely and the exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closing the
thewriter
async with acmanager(writer) as streaming_task: | ||
await asyncio.wait( | ||
[consumer(reader), streaming_task], | ||
return_when=asyncio.FIST_COMPLETED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: FIRST_COMPLETED
No description provided.