question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exceptions are cached?

See original GitHub issue

Hello,

I’m seeing some weird thing with Exception… The lru_cache decorator would not cache anything in case an exception is raised, so something like this:

# not very useful but shows well the difference
foo = 0
@lru_cache(maxsize=10)
def return_something_sync(a):
    global foo
    foo += 1
    raise Exception(foo, time.time())

Would raise something like this:

return_something_sync(1)
>>> Exception: (1, 1564754537.844053)
return_something_sync(1)
>>> Exception: (2, 1564754539.949204)

So a new exception each time. But with alru_cache, the exception itself is cached and raised back!

foo = 0
@alru_cache(maxsize=10)
async def return_something(a):
    global foo
    foo += 1
    raise Exception(foo, time.time())

Will raise:

await return_something(1)
>>> Exception: (1, 1564754484.767096)
await return_something(1)
>>> Exception: (1, 1564754484.767096)

I would expect the exception not to be kept in cache, like for the sync equivalent; otherwise we have basically no way to call again the same function in case of transient issue (which can frequently happen if involving network access…).

Or am I missing something?

Thanks

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
GrazingScientistcommented, Jan 8, 2021

OK… and then after I read the code, and see that there is a cache_exceptions option to turn that off!

Anyway, shouldn’t that option be False by default to be consistent with the sync version?

Totally agree! Thank you for mentioning this parameter! 😃

This parameter (or at least this behaviour of caching exceptions) should be mentioned in the README!

3reactions
RouquinBlanccommented, Aug 2, 2019

OK… and then after I read the code, and see that there is a cache_exceptions option to turn that off!

Anyway, shouldn’t that option be False by default to be consistent with the sync version?

Read more comments on GitHub >

github_iconTop Results From Across the Web

About caching exceptions | cruftex.net
The iteration of the cache entries, never throws an exception. Thus, the CacheEntry interface has the method getException() to check whether ...
Read more >
Cache Exceptions | Apex Reference Guide
Cache Exceptions ; Cache.InvalidParamException, An invalid parameter value is passed into a method of Cache.Session or Cache.Org . This error occurs when: The ......
Read more >
: Class CacheException - Oracle Help Center
CacheException is a generic exception, which indicates a cache error has occurred. All the other cache exceptions are the subclass of this class....
Read more >
Cache Exception Handlers - Ehcache
Caches with ExceptionHandling configured are of type Ehcache. To get the exception handling behaviour they must be referenced using CacheManager.
Read more >
Exceptions are cached? · Issue #162 · aio-libs/async-lru - GitHub
But with alru_cache , the exception itself is cached and raised back! ... I would expect the exception not to be kept in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found