Hi,
I am struggling to port my @async.coroutine <=3.7 to new async 3.9. When I do, I can’t return anything and it forces every caller in the stack to also be labeled async which I cannot do.
@asyncio.coroutine
def get_result(q, func, sleep, pid, timeout):
import queue
import time
while True:
try:
yield time.sleep(sleep)
_result = q.get_nowait()
return _result
except queue.Empty:
import time
yield time.sleep(sleep)
I get the results using this.
_tasks += [get_result(queue, arg, self.sleep, pid, self.timeout)]
tasks = asyncio.gather(*_tasks)
To be clear, I need.
- Coroutine has to return a value
- Coroutine has to be able to yield to event loop
- Calling function cannot also be async
This is the way it currently works. But I can’t make it work this way in 3.9
Any help is appreciated.