-
Notifications
You must be signed in to change notification settings - Fork 61
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
base: master
Are you sure you want to change the base?
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 |
CodSpeed Performance ReportMerging #697 will not alter performanceComparing Summary
|
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. |
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