-
Notifications
You must be signed in to change notification settings - Fork 63
feat: handle CancelledError - cancel if no other waiters #697
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
Conversation
|
Looks like a good idea. Should get a test added that reproduces the issue. |
|
I've added the tests and this is now ready for review. But post-review, let's make sure we merge #688 before this one so we can start populating data in the codspeed dashboard |
|
Looks like there's one complication I didn't consider If the cancelled waiter is the first waiter for a particular cache item, cancelling is easy because the waiter already has the task (it created the task) But if any subsequent waiter is cancelled, that waiter did not create the task and does not have any reference to it. Only the CacheItem's fut. is there any reason the tasks need to go in __tasks or is that just a common place for collection? Would it be acceptable to instead add a That way, each CacheItem would be directly linked to its associated task and any waiter would have access to it for cancellation. |
Not sure. If the tests are passing, then another approach may be fine.
I guess as long as we don't end up with circular references or anything that might causes memory leaks, then it might work. |
c29b492 to
0c0fce7
Compare
|
@Dreamsorcerer I finally found some time to finish this up and add some test cases, not sure if this needs to be documented as it seems like what should be the expected behavior. Lmk what you think! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #697 +/- ##
==========================================
+ Coverage 97.22% 97.28% +0.06%
==========================================
Files 12 13 +1
Lines 793 811 +18
Branches 41 44 +3
==========================================
+ Hits 771 789 +18
Misses 20 20
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c1cb901 to
e85e099
Compare
|
I'm seeing a notable decrease in memory usage on some of my longer-running scripts and services! |
|
Sorry about the delay. Looks all good to me. |
What do these changes do?
Currently if a decorated function is awaited, and then that task is cancelled, async_lru will never cancel the task, potentially leading to memory leaks and other fun things.
In cases where the only waiter is cancelled, this PR will gracefully cancel the task and pop the key
Are there changes in behavior for the user?
Yes, a cancelled task will cancel any cached jobs that haven't completed and have no other waiters.
Related issue number
Checklist