harvimt / quamash

Implementation of the PEP 3156 event-loop (asyncio) api using the Qt Event-Loop
BSD 2-Clause "Simplified" License
265 stars 46 forks source link

exceptions not set on pending futures #109

Open hartytp opened 5 years ago

hartytp commented 5 years ago

The following code snippet should tries to connect to a server that doesn't exist

host = "127.0.0.1"
port = 5000

try:
    print("connecting...")   
    loop = asyncio.get_event_loop()
    loop.run_until_complete(asyncio.open_connection(host, port))
except Exception as e:
    print("exception" , e)
print("done")

Expected behaviour is that a ConnectionRefusedError is raised. Without Quamash, that is what happens. With quamash, run_until_complete never finishes and the following warning is printed

WARNING<7>:quamash._QEventLoop:Event callback failed
Traceback (most recent call last):
  File "c:\scratch\quamash\quamash\_windows.py", line 42, in _process_events
    value = callback(transferred, key, ov)
  File "C:\Users\localadmin\Anaconda3\envs\artiq-env\lib\asyncio\windows_events.py", line 509, in finish_connect
    ov.getresult()
ConnectionRefusedError: [WinError 1225] The remote computer refused the network connection

It looks like the future gets stuck in the PENDING state. I believe this is related to e5fc6b110830ebcc90496da07f1d75064eff6d08

Changing this to

except OSError as e:
    self._logger.warning('Event callback failed', exc_info=sys.exc_info())
    if not f.done():
        f.set_exception(e)

seems to resolve the issue. Thoughts?