Evict failed futures from cache; replace deprecated get_event_loop#13
Closed
jtschoonhoven wants to merge 1 commit intoimnotjames:mainfrom
Closed
Conversation
Failed futures were never removed from the cache after being detected as errored. While the retry-on-error behavior was correct (the function would re-execute), the stale failed future continued to occupy a cache slot. With bounded caches like LRUCache this can evict valid entries. This change explicitly deletes failed futures from the cache before re-executing. Also replaces asyncio.get_event_loop() with asyncio.get_running_loop(), as get_event_loop() has been deprecated since Python 3.10 and these decorators are only called from within async contexts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Owner
|
You have three things in one pull request. I'd prefer these to be separate. |
Owner
|
Can you point where in the docs that |
Author
My bad, there's a DeprecationWarning that fires when there's not already an event loop, but that's not really relevant for this decorator. Dropping this change.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LRUCache), this can cause valid entries to be evicted. This change explicitlydels failed futures before re-executing.get_event_loop()withget_running_loop():asyncio.get_event_loop()has been deprecated since Python 3.10. Since these decorators are only called from within async contexts,get_running_loop()is the correct replacement.Both
cachedandcachedmethodare fixed.Test plan
test_failed_futures_are_evicted_from_cachefor bothcachedandcachedmethodverify that after a failed call, the cache slot is freed and a subsequent successful call populates it correctly🤖 Generated with Claude Code