aio-libs-abandoned/aioredis-py

RuntimeError: There is no current event loop in thread 'MainThread'.

mcrrobinson opened this issue · 2 comments

Describe the bug

Perhaps the same bug that happens in the syncronous version of the Redis client here
Happens when a SIGTERM is fired to the worker.

To Reproduce

  1. Create a uvicorn like server
  2. Add aioredis on an endpoint
  3. Call the endpoint
  4. At some point CTRL+C to the server

Expected behavior

from aioredis import Redis
redis = Redis(host='localhost', decode_responses=True)
redis_client = redis.client()

...

@app.on_event("shutdown")
async def shutdown_event():
    await redis.connection_pool.disconnect()
    await redis.close()

Adding this didn't help as it did here

Should close the server without erroring.

Logs/tracebacks

Exception ignored in: <function Redis.__del__ at 0x7fd693f889d0>
Traceback (most recent call last):
  File "/home/squash/miniconda3/lib/python3.9/site-packages/aioredis/client.py", line 1063, in __del__
  File "/home/squash/miniconda3/lib/python3.9/site-packages/aioredis/client.py", line 916, in __repr__
  File "/home/squash/miniconda3/lib/python3.9/site-packages/aioredis/connection.py", line 1337, in __repr__
  File "/home/squash/miniconda3/lib/python3.9/site-packages/aioredis/connection.py", line 653, in __init__
  File "/home/squash/miniconda3/envs/data_processing/lib/python3.9/asyncio/locks.py", line 81, in __init__
  File "/home/squash/miniconda3/envs/data_processing/lib/python3.9/asyncio/events.py", line 642, in get_event_loop
RuntimeError: There is no current event loop in thread 'MainThread'.

Python Version

$ python --version
Python 3.9.7

aioredis Version

$ python -m pip show aioredis
Name: aioredis
Version: 2.0.1
Summary: asyncio (PEP 3156) Redis support
Home-page: https://github.com/aio-libs/aioredis-py
Author: 
Author-email: 
License: MIT
Location: /home/squash/miniconda3/lib/python3.9/site-packages
Requires: typing-extensions, async-timeout
Required-by:

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
iwpnd commented

@UP2022742 this should be raised over at redis-py now as it is the new home of aioredis.

iwpnd commented

I think you have to either drop your redis_client and pass the redis only, or redis_client.close() in the shutdown. Otherwise the connection will not be cleaned up. @UP2022742