| 248 | |
| 249 | print("Example 9") |
| 250 | async 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 | |
| 268 | print("Example 10") |