-
Notifications
You must be signed in to change notification settings - Fork 49
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
Error with Python 3.10: "ValueError: loop argument must agree with lock" #358
Comments
The code involved here is the Lines 24 to 42 in d7970f8
|
In particular it seems to be these two lines: Lines 38 to 39 in d7970f8
I don't understand how those are any different from doing this:
|
Aha! But that simple >>> async def run():
... print(asyncio.Condition(asyncio.Lock()))
...
>>> asyncio.run(run())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/simon/.pyenv/versions/3.10.0/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/Users/simon/.pyenv/versions/3.10.0/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
return future.result()
File "<stdin>", line 2, in run
File "/Users/simon/.pyenv/versions/3.10.0/lib/python3.10/asyncio/locks.py", line 234, in __init__
raise ValueError("loop argument must agree with lock")
ValueError: loop argument must agree with lock |
Could this be a bug in Python 3.10? |
I filed a Python 3.10 issue about this here: https://bugs.python.org/issue45416 |
I commented on BPO-45416 with a workaround that janus can employ. |
Here's the first of @ambv's suggested workaround (there's a longer but less hacky one in the comment too): >>> l = asyncio.Lock()
>>> getattr(l, '_get_loop', lambda: None)() I'm going to try that against Janus now. |
That addressed the bug! diff --git a/janus/__init__.py b/janus/__init__.py
index 789f12f..a2375b6 100644
--- a/janus/__init__.py
+++ b/janus/__init__.py
@@ -36,6 +36,8 @@ class Queue(Generic[T]):
self._all_tasks_done = threading.Condition(self._sync_mutex)
self._async_mutex = asyncio.Lock()
+ # Workaround for issue #358:
+ getattr(self._async_mutex, '_get_loop', lambda: None)()
self._async_not_empty = asyncio.Condition(self._async_mutex)
self._async_not_full = asyncio.Condition(self._async_mutex)
self._finished = asyncio.Event()
|
I have sent a PR to CPython: python/cpython#28850. |
Co-authored-by: Andrew Svetlov <[email protected]>
janus 0.6.2 released with the fix |
i have same error with django channels |
I ran into this in my own project, see simonw/datasette#1481 - then I tried using a fork of this project to run the unit tests against Python 3.10 and got the same error: https://github.com/simonw/janus/runs/3842463703?check_suite_focus=true
The text was updated successfully, but these errors were encountered: