generated from daniil-berg/boilerplate-py
made start
"non-async" using meta task
This commit is contained in:
@ -39,9 +39,9 @@ async def work(n: int) -> None:
|
||||
|
||||
async def main() -> None:
|
||||
pool = SimpleTaskPool(work, args=(5,)) # initializes the pool; no work is being done yet
|
||||
await pool.start(3) # launches work tasks 0, 1, and 2
|
||||
pool.start(3) # launches work tasks 0, 1, and 2
|
||||
await asyncio.sleep(1.5) # lets the tasks work for a bit
|
||||
await pool.start(1) # launches work task 3
|
||||
pool.start(1) # launches work task 3
|
||||
await asyncio.sleep(1.5) # lets the tasks work for a bit
|
||||
pool.stop(2) # cancels tasks 3 and 2 (LIFO order)
|
||||
await pool.gather_and_close() # awaits all tasks, then flushes the pool
|
||||
|
@ -67,7 +67,7 @@ async def main() -> None:
|
||||
for item in range(100):
|
||||
q.put_nowait(item)
|
||||
pool = SimpleTaskPool(worker, args=(q,)) # initializes the pool
|
||||
await pool.start(3) # launches three worker tasks
|
||||
pool.start(3) # launches three worker tasks
|
||||
control_server_task = await TCPControlServer(pool, host='127.0.0.1', port=9999).serve_forever()
|
||||
# We block until `.task_done()` has been called once by our workers for every item placed into the queue.
|
||||
await q.join()
|
||||
|
Reference in New Issue
Block a user