MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / run_tasks

Function run_tasks

example_code/item_078.py:53–68  ·  view source on GitHub ↗
(handles, interval, output_path)

Source from the content-addressed store, hash-verified

51import asyncio
52
53async def run_tasks(handles, interval, output_path):
54 loop = asyncio.get_event_loop()
55
56 output = await loop.run_in_executor(None, open, output_path, "wb")
57 try:
58
59 async def write_async(data):
60 await loop.run_in_executor(None, output.write, data)
61
62 async with asyncio.TaskGroup() as group:
63 for handle in handles:
64 group.create_task(
65 tail_async(handle, interval, write_async)
66 )
67 finally:
68 await loop.run_in_executor(None, output.close)
69
70
71print("Example 2")

Callers

nothing calls this directly

Calls 1

tail_asyncFunction · 0.70

Tested by

no test coverage detected