MCPcopy Index your code
hub / github.com/python/cpython / test_task_done

Method test_task_done

Lib/test/test_asyncio/test_queues.py:465–494  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

463 self.assertRaises(ValueError, q.task_done)
464
465 async def test_task_done(self):
466 q = self.q_class()
467 for i in range(100):
468 q.put_nowait(i)
469
470 accumulator = 0
471
472 # Two workers get items from the queue and call task_done after each.
473 # Join the queue and assert all items have been processed.
474 running = True
475
476 async def worker():
477 nonlocal accumulator
478
479 while running:
480 item = await q.get()
481 accumulator += item
482 q.task_done()
483
484 async with asyncio.TaskGroup() as tg:
485 tasks = [tg.create_task(worker())
486 for index in range(2)]
487
488 await q.join()
489 self.assertEqual(sum(range(100)), accumulator)
490
491 # close running generators
492 running = False
493 for i in range(len(tasks)):
494 q.put_nowait(0)
495
496 async def test_join_empty_queue(self):
497 q = self.q_class()

Callers

nothing calls this directly

Calls 5

workerFunction · 0.50
put_nowaitMethod · 0.45
create_taskMethod · 0.45
joinMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected