-
Notifications
You must be signed in to change notification settings - Fork 4
Fix RuntimeWarning and DeprecationWarning in test suite #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 8 commits
d48d3b6
36c005b
3bd6271
501715c
ced665b
ca69c14
09bd73c
a212180
289716a
1346ec0
f6c9525
d72930c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,9 @@ | |
| they are functionally identical to the :class:`redis.Redis()` and | ||
| :class:`redis.StrictRedis()` classes. | ||
| """ | ||
| import asyncio | ||
| import atexit | ||
| import inspect | ||
| import json | ||
| import logging | ||
| import os | ||
|
|
@@ -109,7 +111,13 @@ def _cleanup(self, sys_modules=None): | |
| if getattr(self, '_async_managed', False): | ||
| logger.debug('Skipping shutdown for async-managed client') | ||
| return # Let async wrapper handle shutdown | ||
| self.shutdown(save=True, now=True, force=True) | ||
| # Check if shutdown is a coroutine function to avoid async/sync confusion | ||
| if hasattr(self, 'shutdown') and inspect.iscoroutinefunction(self.shutdown): | ||
| # If it's async, use asyncio.run to properly await it | ||
| asyncio.run(self.shutdown(save=True, now=True, force=True)) | ||
| else: | ||
|
Comment on lines
+114
to
+118
|
||
| # Use the normal shutdown method | ||
| self.shutdown(save=True, now=True, force=True) | ||
| try: # pragma: no cover | ||
| process = psutil.Process(pid) | ||
| except psutil.NoSuchProcess: # pragma: no cover | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asyncio.run(...)will raiseRuntimeErrorif_cleanup()executes while an event loop is already running (e.g., in async test environments). Consider handling the 'running loop' case by usingasyncio.get_running_loop()and scheduling the coroutine (e.g.,loop.create_task(...)) when a loop is active, and only falling back toasyncio.run(coro)when there is no running loop.