This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
Coroutine with asyncio.sleep() hangs when run in a different thread #312
Closed
Description
Here is my code:
import asyncio
from threading import Thread
async def onRequest(data):
print('got request: {}'.format(data))
await asyncio.sleep(1)
print('finished processing request {}'.format(data))
loop = asyncio.get_event_loop()
loop.set_debug(True)
def child_executor():
loop.run_forever()
child = Thread(target=child_executor, name="child")
def request(data):
asyncio.run_coroutine_threadsafe(onRequest(data), loop)
child.start()
request(4)
This produces the following output:
got request: 4
and then it just hangs, without the 'finished processing request' message. If I press ctrl^C, it outputs the following message, which doesn't look very interesting:
Exception ignored in: <module 'threading' from '/home/ubuntu/lib/python3.5/threading.py'>
Traceback (most recent call last):
File "/home/ubuntu/lib/python3.5/threading.py", line 1288, in _shutdown
t.join()
File "/home/ubuntu/lib/python3.5/threading.py", line 1054, in join
self._wait_for_tstate_lock()
File "/home/ubuntu/lib/python3.5/threading.py", line 1070, in _wait_for_tstate_lock
elif lock.acquire(block, timeout):
KeyboardInterrupt
Metadata
Metadata
Assignees
Labels
No labels