Skip to content
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

Rewrite context managers (i.e. in caches) with AsyncExitStack #79

Open
dolamroth opened this issue Mar 5, 2024 · 0 comments
Open

Rewrite context managers (i.e. in caches) with AsyncExitStack #79

dolamroth opened this issue Mar 5, 2024 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@dolamroth
Copy link
Owner

Use the following logic: https://github.com/agronholm/apscheduler/blob/master/src/apscheduler/_schedulers/async_.py#L159-L166

basically, enter the exit stack already in __aenter__(), and if all goes well, use the .pop_all() method to extract a new exit stack with all the callbacks for __aexit__() to unwind
this makes sure that the exit stack still unwinds even if there's an exception in __aenter__()
I use this technique everywhere when the logic of __aenter__() is nontrivial
if you don't do this, and __aenter__() raises an exception after you've entered a cancel scope, the entire task is broken beyond repair
``` (c) agronholm
@dolamroth dolamroth added this to the No due date milestone Mar 5, 2024
@dolamroth dolamroth added the enhancement New feature or request label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant