-
Notifications
You must be signed in to change notification settings - Fork 335
Task was destroyed but is is pending #154
Comments
Hi, async def _connect(self):
if self._pool is None:
self._pool = await aioredis.create_pool(
(self.endpoint, self.port))
return self._pool # here no await needed
async def get(self, key):
async with await self._connect() as client: # use 'async with'
await client.get(key) |
Thanks for the quick response! With the changes it gives the following error: > async with await self._connect() as client:
E AttributeError: __aexit__ |
try without |
Not working: aiocache/redis.py:50: in set
with await self._connect() as redis:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <aioredis.pool.RedisPool object at 0x7f4a452acf60>
def __enter__(self):
raise RuntimeError(
> "'yield from' should be used as a context manager expression")
E RuntimeError: 'yield from' should be used as a context manager expression
../../.virtualenvs/aiocache/lib/python3.5/site-packages/aioredis/pool.py:256: RuntimeError The only way I've been able to make it work is with the first version I posted in the first message |
async def _connect(self):
if self._pool is None:
self._pool = await aioredis.create_pool(
(self.endpoint, self.port))
return self._pool # here no await needed
async def get(self, key):
async with (await self._connect()).get() as client: # use 'async with'
await client.get(key) this works for me |
Yeah, and it does for me too. Also the first code I posted does. I opened this because for every operation this message seems to appear so it seems something is not being completed or closed correctly. With the code you posted it also happens (I adapted it to run it from a main): import aioredis
import asyncio
async def _connect():
_pool = await aioredis.create_pool(
("127.0.0.1", 6379))
return _pool
async def get(key):
async with (await _connect()).get() as client: # use 'async with'
await client.get(key)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(get("key")) This shows the following in the output: 23:24 $ python main.py
None
Task was destroyed but it is pending!
task: <Task pending coro=<RedisPool._do_close() done, defined at /home/blck/.virtualenvs/aiocache/lib/python3.5/site-packages/aioredis/pool.py:100> wait_for=<Future pending cb=[Task._wakeup()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<RedisConnection._read_data() running at /home/blck/.virtualenvs/aiocache/lib/python3.5/site-packages/aioredis/connection.py:131> wait_for=<Future pending cb=[Task._wakeup()]> cb=[Future.set_result()]> |
This is expected behavior as |
Ummm interesting. And shouldn't the pool be closed with the The code implementing the connect call is at https://github.com/argaen/aiocache/blob/master/aiocache/backends/redis.py#L94 Thanks a lot for your time :) |
No problem)
No this will result in new establishing new connection to redis for every
To make redis closable backend should be instantiated and used explicitly so that one could call def main(loop):
redis_backend = config_default_backend(...)
try:
loop.run_until_complete(run_main_program())
finally:
redis_backend._pool.close()
loop.run_until_complete(redis_backend._pool.wait_closed()) |
Nope, in pytest 3.0 if a fixture has a D'oh! I thought @pytest.fixture
def redis_cache(event_loop, mocker):
cache = RedisCache(namespace="test", loop=event_loop)
yield cache
event_loop.run_until_complete(cache.delete(KEY))
event_loop.run_until_complete(cache.delete("random"))
cache._pool.close()
event_loop.run_until_complete(cache._pool.wait_closed()) works perfectly. Thanks a lot for the help! |
I'm still receiving this error, I'm using FastAPI with aioredis for caching My pool code
It doesn't work either with |
@popravich Can you help me, maybe I'm doing something wrong in my Pool, I tried a lot of variants of this code - the result is the same
|
just solved this by downgrade python to 3.6 |
Hi, I'm receiving multiple messages stating the following:
The code I'm using:
Am I missing something? Isn't the context_manager supposed to close the pool when exits?
Thanks!
The text was updated successfully, but these errors were encountered: