erdewit/nest_asyncio

Websocket hangs with Windows and Python 3.8

jyu00 opened this issue · 5 comments

jyu00 commented

Connection via websockets hangs when running on Windows with Python 3.8, nest_asyncio, and the default WindowsProactorEventLoopPolicy. A simple program can reproduce this:

import asyncio
import nest_asyncio
from websockets import connect

nest_asyncio.apply()

async def _connect():
    websocket = await connect('wss://wss.foo.com:9876')

def client():
    loop = asyncio.get_event_loop()
    return loop.run_until_complete(_connect())

if __name__ == "__main__":
    client()

This works on other platforms/Python versions/policy, or without nest_asyncio. I did a little bit of tracing, and it looks like the connect() completed successfully, but it somehow got stuck when selecting the next event.

In the script to reproduce the issue it seems that the definition for job_status is omitted.

jyu00 commented

Yeah sorry the simplified version should not have job_status. Updated the original text.

pip install nest_asyncio==1.3.3 fixes it.

I can reproduce the issue on Windows 10, Python 3.9. The issue is the ProactorEvenLloop getting a timeout of None in a select call, which then leaves it hanging. A work-around has been added to use a definite timeout value instead of None.

This is released now in v1.4.2.