| 194 | # policy = asyncio.get_event_loop_policy() |
| 195 | # policy._loop_factory = asyncio.SelectorEventLoop |
| 196 | async def run_tasks_mixed(handles, interval, output_path): |
| 197 | loop = asyncio.get_event_loop() |
| 198 | |
| 199 | output = await loop.run_in_executor(None, open, output_path, "wb") |
| 200 | try: |
| 201 | |
| 202 | async def write_async(data): |
| 203 | await loop.run_in_executor(None, output.write, data) |
| 204 | |
| 205 | def write(data): |
| 206 | coro = write_async(data) |
| 207 | future = asyncio.run_coroutine_threadsafe(coro, loop) |
| 208 | future.result() |
| 209 | |
| 210 | tasks = [] |
| 211 | for handle in handles: |
| 212 | task = loop.run_in_executor( |
| 213 | None, tail_file, handle, interval, write |
| 214 | ) |
| 215 | tasks.append(task) |
| 216 | |
| 217 | await asyncio.gather(*tasks) |
| 218 | finally: |
| 219 | await loop.run_in_executor(None, output.close) |
| 220 | |
| 221 | |
| 222 | print("Example 7") |