[Feature]: Lifecycle management for asyncstdlib-created iterators
#166
Replies: 1 comment
-
|
Thanks for the questions! I've moved this to Discussions since that seems more appropriate in this case - feel free to open another issue if you have a specific request. Cleanup in generalIndeed That said, missing out on closing an async iterator/generator is not the end of the world. Async generator cleanup is weird if you try and hit every edge case (see e.g. python-trio/trio#265 if you have too much time) so just do your best. Cleanup for
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the feature
This might be more of a request for usage guidance than one for new features. If I have an AsyncGenerator
agen()and I pass it into one of theasyncstdlibiterators, sayenumerate, my understanding isenumeratenow ties the cleanup ofagento its own cleanup. But that doesn't meanenumerate(agen())is deterministically cleaned-up -- for instance, in the following scenario:So would the correct solution in this case be to wrap the entire code block in
async with asyncstdlib.scoped_iter(asyncstdlib.enumerate(agen())) as safe_enum_itand iterate onsafe_enum_itinstead?A potentially related situation is with how
asyncstdlib.listowns the internal iterable. If I just doa = await asyncstdlib.list(agen()), and for some reason (maybe an external exception) the execution is interrupted andagen()doesn't finish iterating, would it be correct to assume that the cleanup isn't guaranteed to happen, and we should ideally do something likeinstead?
I really love this library, so would really appreciate your explanation on this. Thank you!
Request Assignment [Optional]
Beta Was this translation helpful? Give feedback.
All reactions