-
Notifications
You must be signed in to change notification settings - Fork 336
Wierd error on function exception #159
Comments
Sorry, it's impossible to give a correct answer without digging into your code but console output means that on exception you are trying to destroy redis pool. |
Hi @argaen,
I would recomend implementing option i — this would allow to reuse single RedisPool for whole application. |
But why this error only appears when an exception is raised from the function the decorator is calling and not always? @popravich this is related to the comment I did in #129 (comment). I would like to keep the logic inside the Regarding the ii option this means that I should anyway try to catch the |
Can you attach the traceback when this warning appears with exception in |
I've written this simple example: import asyncio
from aiocache import RedisCache, cached
@cached(cache=RedisCache)
async def call_to_redis_exception():
raise ValueError()
@cached(cache=RedisCache)
async def call_to_redis():
return "1"
async def wrapper():
try:
print("EXCEPTION CALL")
await call_to_redis_exception()
except ValueError:
print("Value error triggered")
print("NO EXCEPTION CALL")
await call_to_redis()
def test_redis():
loop = asyncio.get_event_loop()
loop.run_until_complete(wrapper())
if __name__ == "__main__":
test_redis() By executing it I'm obtaining: 18:09 $ python examples/raise_exception.py
ujson module not found, usin json
cPickle module not found, using pickle
EXCEPTION CALL
Value error triggered
NO EXCEPTION CALL
Task was destroyed but it is pending!
task: <Task pending coro=<RedisPool._do_close() running at /Users/manuelmiranda/.virtualenvs/aiocache/lib/python3.5/site-packages/aioredis/pool.py:102> wait_for=<Future pending cb=[Task._wakeup()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<RedisPool._do_close() running at /Users/manuelmiranda/.virtualenvs/aiocache/lib/python3.5/site-packages/aioredis/pool.py:102> wait_for=<Future pending cb=[Task._wakeup()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<RedisConnection._read_data() running at /Users/manuelmiranda/.virtualenvs/aiocache/lib/python3.5/site-packages/aioredis/connection.py:131> wait_for=<Future pending cb=[Task._wakeup()]> cb=[Future.set_result()]>
Task was destroyed but it is pending!
task: <Task pending coro=<RedisConnection._read_data() running at /Users/manuelmiranda/.virtualenvs/aiocache/lib/python3.5/site-packages/aioredis/connection.py:131> wait_for=<Future pending cb=[Task._wakeup()]> cb=[Future.set_result()]> BUT, If I comment the function triggering the exception, no messages regarding Task pending appear. |
ok, the problem why this warnings come from |
I think this is because |
Oh man, true that. Anyway, if you check the if await cache.exists(cache_key):
return await cache.get(cache_key)
else:
res = await fn(*args, **kwargs)
await cache.set(cache_key, res, ttl=ttl)
return res If no exception is raised from Do the connections from the |
This warning messages is thrown when task gets deleted, so you may not see it until task is garbage collected (possibly until loop is destroyed or program exit). |
Hi, I have the following code:
The problem is that if
fn
raises an exception, the following appears on the console:The one giving those warnings is the
cache.exists
function which basically does:Sorry for pasting all the code but I thought the context of executing within a decorator may be important.
Do you have any idea of what is going on? Is it because I'm defining the
cache
variable outside the function that gets executed??The text was updated successfully, but these errors were encountered: