-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-96471: Add asyncio queue shutdown #104228
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 1 commit
440a702
fb458db
e5951ac
a72aedd
d5e925d
f3517fb
bd2a7c3
e9ac8de
1e7813a
1275bb6
eec29bb
2c6156f
17f1f32
a233830
420a247
25ad2ac
f3321b4
6d9edd6
1135d85
ddc6ad6
2fa1bd9
aef4063
d49c6dd
5a435a6
c8db40e
ca01ee1
b02c4dd
8deca77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
* Explicit 'immediate' argument * All tests test '*_nowait' * All tests check 'qsize'
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -544,22 +544,33 @@ async def test_shutdown_empty(self): | |
| q = self.q_class() | ||
| loop = asyncio.get_running_loop() | ||
| join_task = loop.create_task(q.join()) | ||
| q.shutdown() | ||
| q.shutdown(immediate=False) # unfinished tasks: 0 -> 0 | ||
|
|
||
| self.assertEqual(q.qsize(), 0) | ||
|
|
||
| await self._ping_awaitable(join_task) | ||
| self.assertTrue(join_task.done()) | ||
|
|
||
| with self.assertRaisesShutdown(): | ||
| await q.put("data") | ||
| with self.assertRaisesShutdown(): | ||
| q.put_nowait("data") | ||
|
|
||
| with self.assertRaisesShutdown(): | ||
| await q.get() | ||
| with self.assertRaisesShutdown(): | ||
| q.get_nowait() | ||
|
|
||
| await join_task | ||
|
|
||
| async def test_shutdown_nonempty(self): | ||
| q = self.q_class() | ||
| loop = asyncio.get_running_loop() | ||
| q.put_nowait("data") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this scenario the two are equivalent (the queue is not empty, there are no other tasks scheduled), so I thought |
||
| join_task = loop.create_task(q.join()) | ||
| q.shutdown() | ||
| q.shutdown(immediate=False) # unfinished tasks: 1 -> 1 | ||
|
|
||
| self.assertEqual(q.qsize(), 1) | ||
|
|
||
| self.assertEqual(await q.get(), "data") | ||
|
|
||
|
|
@@ -587,7 +598,9 @@ async def test_shutdown_immediate(self): | |
| loop = asyncio.get_running_loop() | ||
| q.put_nowait("data") | ||
| join_task = loop.create_task(q.join()) | ||
| q.shutdown(immediate=True) | ||
| q.shutdown(immediate=True) # unfinished tasks: 1 -> 0 | ||
|
|
||
| self.assertEqual(q.qsize(), 0) | ||
|
|
||
| await self._ping_awaitable(join_task) | ||
|
EpicWink marked this conversation as resolved.
Outdated
|
||
| self.assertTrue(join_task.done()) | ||
|
|
@@ -607,8 +620,6 @@ async def test_shutdown_immediate(self): | |
| ): | ||
| q.task_done() | ||
|
|
||
| await self._ping_awaitable(join_task) | ||
| self.assertTrue(join_task.done()) | ||
| await join_task | ||
|
|
||
| async def test_shutdown_immediate_with_unfinished(self): | ||
|
|
@@ -618,7 +629,7 @@ async def test_shutdown_immediate_with_unfinished(self): | |
| q.put_nowait("data") | ||
| join_task = loop.create_task(q.join()) | ||
| self.assertEqual(await q.get(), "data") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and testing on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Except when
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have implemented your suggestion, but I have not committed. I am considering it. I don't think it's necessary.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test case (thus including |
||
| q.shutdown(immediate=True) | ||
| q.shutdown(immediate=True) # unfinished tasks: 2 -> 1 | ||
|
|
||
|
EpicWink marked this conversation as resolved.
|
||
| await self._ping_awaitable(join_task) | ||
| self.assertFalse(join_task.done()) | ||
|
|
||
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.
Since you have these I'm not sure why you also have a task exercising
q.get()?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.
I'm testing
await q.get()raises after shutting down here, but for the previous task the get() is started before the shut down