question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error with Python 3.10: "ValueError: loop argument must agree with lock"

See original GitHub issue

I ran into this in my own project, see https://github.com/simonw/datasette/pull/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

 ============================= test session starts ==============================
 platform linux -- Python 3.10.0, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
 rootdir: /home/runner/work/janus/janus
 plugins: cov-2.12.1, asyncio-0.15.1
 collected 72 items
 
 tests/test_async.py FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF                      [ 43%]
 tests/test_mixed.py .FFFFFFFFFFFFFFFFF                                   [ 68%]
 tests/test_sync.py FFFFFFFFFFFFFFFFFFFFFFF                               [100%]
 
 =================================== FAILURES ===================================
 __________________________ TestQueueBasic.test_empty ___________________________
 
 self = <test_async.TestQueueBasic object at 0x7fb0f561e4d0>
 
     @pytest.mark.asyncio
     async def test_empty(self):
 >       _q = janus.Queue()
 
 tests/test_async.py:65: 
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 janus/__init__.py:39: in __init__
     self._async_not_empty = asyncio.Condition(self._async_mutex)
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 
 self = <[AttributeError("'Condition' object has no attribute 'locked'") raised in repr()] Condition object at 0x7fb0f569a620>
 lock = <asyncio.locks.Lock object at 0x7fb0f569ada0 [unlocked]>
 
     def __init__(self, lock=None, *, loop=mixins._marker):
         super().__init__(loop=loop)
         if lock is None:
             lock = Lock()
         elif lock._loop is not self._get_loop():
 >           raise ValueError("loop argument must agree with lock")
 E           ValueError: loop argument must agree with lock

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
asvetlovcommented, Oct 24, 2021

janus 0.6.2 released with the fix

1reaction
simonwcommented, Oct 8, 2021

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()

(janus) janus % pytest -x      
============================================================= test session starts ==============================================================
platform darwin -- Python 3.10.0, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /Users/simon/Dropbox/Development/janus
plugins: cov-2.12.1, asyncio-0.15.1
collected 72 items                                                                                                                             

tests/test_async.py ...............................                                                                                      [ 43%]
tests/test_mixed.py ..................                                                                                                   [ 68%]
tests/test_sync.py .......................                                                                                               [100%]

============================================================== 72 passed in 5.34s ==============================================================
Read more comments on GitHub >

github_iconTop Results From Across the Web

"loop argument must agree with lock" instantiating asyncio ...
In Python 3.10 it is not possible to instantiate an asyncio.Condition that wraps an asyncio.Lock without raising a "loop argument must agree ......
Read more >
Finding and reporting an asyncio bug in Python 3.10
Finding and reporting an asyncio bug in Python 3.10 ... Lock() # "loop argument must agree with lock" exception is raised here: self....
Read more >
python 3.6 and ValueError: loop argument must agree with ...
I just want to run a simple test example yet I get the below error. How do I resolve?
Read more >
Python: Lib/asyncio/locks.py - Fossies
_loop = loop 84 warnings.warn("The loop argument is deprecated since Python 3.8, " 85 "and scheduled for removal in Python 3.10.
Read more >
Python 3.10: Cool New Features for You to Try
In this tutorial, you'll learn about: Debugging with more helpful and precise error messages; Using structural pattern matching to work with data structures ......
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