async def cond_go(): ntasks = 7 barrier = Barrier(ntasks + 1) t1 = asyncio.create_task(cond01()) t3 = asyncio.create_task(cond03()) for n in range(ntasks): asyncio.create_task(cond02(n, barrier)) await barrier # All instances of cond02 have completed # Test wait_for barrier = Barrier(2) asyncio.create_task(cond04(99, barrier)) await barrier # cancel continuously running coros. t1.cancel() t3.cancel() await asyncio.sleep_ms(0) print('Done.')
async def do_barrier_test(): barrier = Barrier(3, callback, ('Synch', )) for _ in range(2): for _ in range(3): asyncio.create_task(report(barrier)) await asyncio.sleep(1) print() await asyncio.sleep(1)
async def main(): sw1 = asyncio.StreamWriter(UART(1, 9600), {}) sw2 = asyncio.StreamWriter(UART( 1, 1200), {}) # ESP32S2 UART(0) is disabled (dedicated to REPL) barrier = Barrier(3) for n, sw in enumerate((sw1, sw2)): asyncio.create_task(sender(barrier, sw, n + 1)) await provider(barrier)
async def bart(): barrier = Barrier(4, my_coro, ('my_coro running', )) for x in range(3): asyncio.create_task(report1(barrier, x)) await barrier # Must yield before reading result(). Here we wait long enough for await asyncio.sleep_ms(1500) # coro to print barrier.result().cancel() await asyncio.sleep(2)
def barrier_test(): printexp('''0 0 0 Synch 1 1 1 Synch 2 2 2 Synch 3 3 3 Synch 4 4 4 Synch ''') barrier = Barrier(3, callback, ('Synch', )) for _ in range(3): asyncio.create_task(report(barrier)) asyncio.run(killer(2))
async def run_sema_test(bounded): num_coros = 5 barrier = Barrier(num_coros + 1) if bounded: semaphore = BoundedSemaphore(3) else: semaphore = Semaphore(3) for n in range(num_coros): asyncio.create_task(run_sema(n, semaphore, barrier)) await barrier # Quit when all coros complete try: semaphore.release() except ValueError: print('Bounded semaphore exception test OK')