Task was destroyed but is is pending

See original GitHub issue

Hi, I’m receiving multiple messages stating the following:

Task was destroyed but it is pending!
task: <Task pending coro=<RedisPool._do_close() running at /Users/manuelmiranda/.virtualenvs/redis-cache/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/redis-cache/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!

The code I’m using:

    async def _connect(self):
        if self._pool is None:
            self._pool = await aioredis.create_pool(
                (self.endpoint, self.port))

        return await self._pool

    async def get(self, key):
        with await self._connect() as client:
                await client.get(key)

Am I missing something? Isn’t the context_manager supposed to close the pool when exits?

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
jp3049commented, Jan 21, 2021

@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

Task was destroyed but it is pending! task: <Task pending name='Task-57663' coro=<RedisConnection._read_data() done, defined at /layers/google.python.pip/pip/lib/python3.8/site-packages/aioredis/connection.py:180> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x3ea2c3b858b0>()]> cb=[RedisConnection.__init__.<locals>.<lambda>() at /layers/google.python.pip/pip/lib/python3.8/site-packages/aioredis/connection.py:168]>

just solved this by downgrade python to 3.6

2reactions
argaencommented, Oct 5, 2016

test_redis.py: should not redis_cache fixture be a yield_fixture? maybe that is a problem… You can check aioredis test fixtures.

Nope, in pytest 3.0 if a fixture has a yield it implicitly becomes an “old” yield_fixture. It works out of the box now.

D’oh! I thought close() and wait_closed() were just the sync and async ways to close the redis connection respectively, my bad. After transforming the fixture to:

@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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Please explain "Task was destroyed but it is pending!" after ...
The problem comes from closing the loop immediately after cancelling the tasks. As the cancel() docs state.
Read more >
Task was destroyed but it is pending · Issue #1634 - GitHub
Problem with celery task, that aggregates media from some channels. Previously i tried "sync" version of TelethonClient and got same errors.
Read more >
Task was destroyed but it is pending! - Questions and Help
I'm having a hard time trying to avoid the following issue: Task was destroyed but it is pending! This is related to the...
Read more >
Common Mistakes Using Python3 asyncio
3 Task was destroyed but it is pending! The cause of this problem is that the EventLoop closed right after canceling pending tasks....
Read more >
ERROR Task was destroyed but it is pending! - Google Groups
Dear oTree community,. Can anyone help me with the following error that I receive in the command line (Mac)? I get it since...
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