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

Function run_tasks_mixed

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

Source from the content-addressed store, hash-verified

194# policy = asyncio.get_event_loop_policy()
195# policy._loop_factory = asyncio.SelectorEventLoop
196async 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
222print("Example 7")

Callers 1

item_077.pyFile · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected