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

Function run_tasks

example_code/item_077.py:250–265  ·  view source on GitHub ↗
(handles, interval, output_path)

Source from the content-addressed store, hash-verified

248
249print("Example 9")
250async def run_tasks(handles, interval, output_path):
251 loop = asyncio.get_event_loop()
252
253 output = await loop.run_in_executor(None, open, output_path, "wb")
254 try:
255
256 async def write_async(data):
257 await loop.run_in_executor(None, output.write, data)
258
259 async with asyncio.TaskGroup() as group:
260 for handle in handles:
261 group.create_task(
262 tail_async(handle, interval, write_async)
263 )
264 finally:
265 await loop.run_in_executor(None, output.close)
266
267
268print("Example 10")

Callers 1

item_077.pyFile · 0.70

Calls 1

tail_asyncFunction · 0.70

Tested by

no test coverage detected