Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
440a702
Add asyncio queue shutdown
EpicWink Sep 1, 2022
fb458db
Fix queue shutdown
YvesDup Feb 10, 2023
e5951ac
πŸ“œπŸ€– Added by blurb_it.
blurb-it[bot] May 6, 2023
a72aedd
Merge remote-tracking branch 'upstream/main' into asyncio-queue-shutdown
EpicWink Feb 20, 2024
d5e925d
Add references in docs and news entry
EpicWink Feb 20, 2024
f3517fb
Merge remote-tracking branch 'upstream/main' into asyncio-queue-shutdown
EpicWink Mar 20, 2024
bd2a7c3
Improve docs
EpicWink Mar 20, 2024
e9ac8de
Consume queue on immediate shutdown
EpicWink Mar 20, 2024
1e7813a
Fix links in what's-new
EpicWink Mar 22, 2024
1275bb6
Merge remote-tracking branch 'upstream/main' into asyncio-queue-shutdown
EpicWink Mar 22, 2024
eec29bb
Fix formatting in news entry
EpicWink Mar 22, 2024
2c6156f
Merge remote-tracking branch 'upstream/main' into asyncio-queue-shutdown
EpicWink Mar 22, 2024
17f1f32
Merge remote-tracking branch 'upstream/main' into asyncio-queue-shutdown
EpicWink Mar 26, 2024
a233830
Improve tests
EpicWink Mar 26, 2024
420a247
Improve tests even more
EpicWink Mar 26, 2024
25ad2ac
Merge remote-tracking branch 'upstream/main' into asyncio-queue-shutdown
EpicWink Mar 26, 2024
f3321b4
Merge remote-tracking branch 'upstream/main' into asyncio-queue-shutdown
EpicWink Mar 27, 2024
6d9edd6
Document tests
EpicWink Mar 27, 2024
1135d85
Merge remote-tracking branch 'upstream/main' into asyncio-queue-shutdown
EpicWink Mar 28, 2024
ddc6ad6
Always allow getters to re-check queue empty
EpicWink Mar 28, 2024
2fa1bd9
Merge branch 'main' into asyncio-queue-shutdown
gvanrossum Apr 3, 2024
aef4063
Simplify shutdown-check in put and get
EpicWink Apr 4, 2024
d49c6dd
Format shutdown docstring
EpicWink Apr 4, 2024
5a435a6
Check for 0 unfinised tasks in shutdown
EpicWink Apr 4, 2024
c8db40e
Use asyncio.sleep to run other tasks
EpicWink Apr 4, 2024
ca01ee1
Use public method to shut down queue in format test
EpicWink Apr 4, 2024
b02c4dd
Only start queue join after shutdown in test
EpicWink Apr 4, 2024
8deca77
Test join before failing task-done
EpicWink Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use asyncio.sleep to run other tasks
  • Loading branch information
EpicWink committed Apr 4, 2024
commit c8db40ed8c4b3eb5722217b6905db07873b9d535
32 changes: 9 additions & 23 deletions Lib/test/test_asyncio/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,21 +525,6 @@ class PriorityQueueJoinTests(_QueueJoinTestMixin, unittest.IsolatedAsyncioTestCa
class _QueueShutdownTestMixin:
q_class = None

@staticmethod
async def _ensure_started(task):
# Explicitly start (if not already) task

async def swallow(x):
try:
return await x
except Exception:
pass

try:
await asyncio.wait_for(asyncio.shield(swallow(task)), 0.01)
except TimeoutError:
pass

def assertRaisesShutdown(self, msg="Didn't appear to shut-down queue"):
return self.assertRaises(asyncio.QueueShutDown, msg=msg)

Expand All @@ -556,7 +541,7 @@ async def test_shutdown_empty(self):
loop = asyncio.get_running_loop()
join_task = loop.create_task(q.join())
get_task = loop.create_task(q.get())
await self._ensure_started(get_task) # want pending before shutdown
await asyncio.sleep(0) # want get task pending before shutdown

# Perform shut-down
q.shutdown(immediate=False) # unfinished tasks: 0 -> 0
Expand All @@ -569,6 +554,7 @@ async def test_shutdown_empty(self):
await join_task

# Ensure get() task is finished, and raised ShutDown
await asyncio.sleep(0)
self.assertTrue(get_task.done())
with self.assertRaisesShutdown():
await get_task
Expand Down Expand Up @@ -596,7 +582,7 @@ async def test_shutdown_nonempty(self):
put_task = loop.create_task(q.put("data2"))

# Ensure put() task is not finished
await self._ensure_started(put_task)
await asyncio.sleep(0)
self.assertFalse(put_task.done())

# Perform shut-down
Expand All @@ -605,7 +591,7 @@ async def test_shutdown_nonempty(self):
self.assertEqual(q.qsize(), 1)

# Ensure put() task is finished, and raised ShutDown
await self._ensure_started(put_task)
await asyncio.sleep(0)
self.assertTrue(put_task.done())
with self.assertRaisesShutdown():
await put_task
Expand All @@ -614,7 +600,7 @@ async def test_shutdown_nonempty(self):
self.assertEqual(await q.get(), "data")

# Ensure join() task is not finished
await self._ensure_started(join_task)
await asyncio.sleep(0)
self.assertFalse(join_task.done())

# Ensure put() and get() raise ShutDown
Expand All @@ -636,7 +622,7 @@ async def test_shutdown_nonempty(self):
q.task_done()

# Ensure join() task has successfully finished
await self._ensure_started(join_task)
await asyncio.sleep(0)
self.assertTrue(join_task.done())
await join_task

Expand All @@ -655,7 +641,7 @@ async def test_shutdown_immediate(self):
self.assertEqual(q.qsize(), 0)

# Ensure join() task has successfully finished
await self._ensure_started(join_task)
await asyncio.sleep(0)
self.assertTrue(join_task.done())
await join_task

Expand Down Expand Up @@ -693,7 +679,7 @@ async def test_shutdown_immediate_with_unfinished(self):
self.assertEqual(q.qsize(), 0)

# Ensure join() task is not finished
await self._ensure_started(join_task)
await asyncio.sleep(0)
self.assertFalse(join_task.done())

# Ensure put() and get() raise ShutDown
Expand All @@ -715,7 +701,7 @@ async def test_shutdown_immediate_with_unfinished(self):
q.task_done()

# Ensure join() task has successfully finished
await self._ensure_started(join_task)
await asyncio.sleep(0)
self.assertTrue(join_task.done())
await join_task

Expand Down