-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
bpo-45416: Fix use of asyncio.Condition() with explicit Lock objects #28850
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
Changes from 2 commits
381e50d
1a6185e
a156f1f
ac0645d
50c68c5
fae4b91
615ce7b
b62d675
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -720,24 +720,39 @@ async def f(): | |||||||
| self.loop.run_until_complete(f()) | ||||||||
|
|
||||||||
| def test_explicit_lock(self): | ||||||||
| lock = asyncio.Lock() | ||||||||
| cond = asyncio.Condition(lock) | ||||||||
| async def f(): | ||||||||
| lock = asyncio.Lock() | ||||||||
| cond = asyncio.Condition(lock) | ||||||||
| self.assertIs(cond._lock, lock) | ||||||||
| # should work same! | ||||||||
| self.assertFalse(cond.locked()) | ||||||||
| async with cond: | ||||||||
| self.assertTrue(cond.locked()) | ||||||||
serhiy-storchaka marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| self.assertFalse(cond.locked()) | ||||||||
|
|
||||||||
| self.assertIs(cond._lock, lock) | ||||||||
| self.assertIs(cond._loop, lock._loop) | ||||||||
| self.loop.run_until_complete(f()) | ||||||||
|
|
||||||||
| def test_ambiguous_loops(self): | ||||||||
| loop = self.new_test_loop() | ||||||||
| self.addCleanup(loop.close) | ||||||||
|
|
||||||||
| lock = asyncio.Lock() | ||||||||
| loop = asyncio.new_event_loop() | ||||||||
| self.addCleanup(loop.close) | ||||||||
| lock._loop = loop | ||||||||
|
||||||||
|
|
||||||||
| async def _create_condition(): | ||||||||
| with self.assertRaises(ValueError): | ||||||||
| asyncio.Condition(lock) | ||||||||
| async def f(): | ||||||||
| async with lock: | ||||||||
| # acquired immediately via the fast-path | ||||||||
| # without interaction with any event loop. | ||||||||
| cond = asyncio.Condition(lock) | ||||||||
| # cond will trigger waiting on the lock | ||||||||
| # and it will discover the event loop mismatch. | ||||||||
| with self.assertRaisesRegex( | ||||||||
| RuntimeError, | ||||||||
| "is bound to a different event loop", | ||||||||
| ): | ||||||||
| async with cond: | ||||||||
| pass | ||||||||
|
||||||||
| async with cond: | |
| pass | |
| await cond.acquire() |
It is raised because cond.acquire is the same as lock.acquire, and the latter fails because its loop is different.
But it would be nice to test less trivial case: cond.wait() which should raise RuntimeError in different code.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix use of :class:`asyncio.Condition` with explicit :class:`asyncio.Lock` objects, which was a regression due to removal of explicit loop arguments. | ||
| Patch by Joongi Kim. |
Uh oh!
There was an error while loading. Please reload this page.