I am trying to get asyncio working with subprocesses and restrictions. I am doing this in a functional way, but when I tried to implement the same opp-style logic, several problems appeared. Basically, it is not possible to sort the coprocessor / generator errors. I followed some of them, but not all
import asyncio from concurrent.futures import ProcessPoolExecutor from itertools import islice from random import randint class async_runner(object): def __init__(self): self.futures = []
But this works great:
import asyncio from concurrent.futures import ProcessPoolExecutor from itertools import islice import time async def asy(x): print('enter: ', x) await asyncio.sleep(1) print('finishing ', x) return x def run(corofn, *args): loop = asyncio.new_event_loop() try: coro = corofn(*args) asyncio.set_event_loop(loop) ret = loop.run_until_complete(coro)
I canβt understand why the multiprocessor module tries to reveal something only when objects are used, but not in any scenario
source share