Skip to content
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

Description

@mikeyhew

Here is my code:

importasynciofromthreadingimportThreadasyncdefonRequest(data):
print('got request: {}'.format(data))
awaitasyncio.sleep(1)
print('finished processing request {}'.format(data))
loop=asyncio.get_event_loop()
loop.set_debug(True)
defchild_executor():
loop.run_forever()
child=Thread(target=child_executor, name="child")
defrequest(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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions