Comments (11)
janus 0.6.2 released with the fix
from janus.
Could this be a bug in Python 3.10?
from janus.
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 ==============================================================
from janus.
The code involved here is the Queue
constructor:
Lines 24 to 42 in d7970f8
from janus.
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: asyncio.Condition(asyncio.Lock())
- which works fine when I try it in the Python 3.10 interpreter:
~ % /Users/simon/.pyenv/versions/3.10.0/bin/python
Python 3.10.0 (default, Oct 7 2021, 13:45:58) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> asyncio.Condition(asyncio.Lock())
<asyncio.locks.Condition object at 0x10ace2110 [unlocked]>
from janus.
Aha! But that simple asyncio.Condition(asyncio.Lock())
line DOES fail if it runs inside an event loop:
>>> 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
from janus.
I filed a Python 3.10 issue about this here: https://bugs.python.org/issue45416
from janus.
I commented on BPO-45416 with a workaround that janus can employ.
from janus.
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.
from janus.
I have sent a PR to CPython: python/cpython#28850.
from janus.
i have same error with django channels
from janus.
Related Issues (20)
- Issue Passing Element Into Queue Right Before Co-Routine Completes HOT 2
- `RuntimeError: no running event loop` after upgrading to 0.5.0 HOT 6
- Inaccurate dependence python 3.5.3 - because of typing.Deque HOT 4
- formatting tests fail HOT 1
- One out of multiple thread consumers hogs queue if consumers count is > 10 HOT 1
- The 'timeout' arg should be typed as (optional) float instead of int HOT 1
- Dependabot couldn't authenticate with https://pypi.python.org/simple/
- join() calls should raise RuntimeError while the queue is closing or closed. HOT 3
- the perfomance is very bad HOT 2
- Exception Handling Question HOT 1
- Janus queues should be creatable in synchronous code as well as in asynchronous code HOT 2
- using deque HOT 2
- What is the correct way to type annotate a janus.Queue? HOT 3
- Performance benefits? HOT 4
- Double-ended Queue Support
- No running event loop HOT 6
- Use AnyIO (optionally) HOT 1
- Task was destroyed but it is pending HOT 1
- Support an atomic `.clear()` operation.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from janus.