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

quamash along with asyncio doesn't seem to catch exceptions correctly #91

Open argoneuscze opened 6 years ago

argoneuscze commented 6 years ago

Hello,

I have this minimal code to reproduce the problem:

import asyncio
import sys

from PyQt5.QtWidgets import QApplication
from quamash import QEventLoop

def problem():
    app = QApplication(sys.argv)
    loop = QEventLoop(app)
    asyncio.set_event_loop(loop)

    loop.run_until_complete(conn())

async def conn():
    try:
        reader, writer = await asyncio.open_connection('127.0.0.1', 7777)
    except ConnectionRefusedError:
        print('exception?')

problem()

When the target server is down, it should catch the exception and print the text. But what actually happens is this error:

Event callback failed
Traceback (most recent call last):
  File "D:\Documents\Programming\venv\lib\site-packages\quamash\_windows.py", line 42, in _process_events
    value = callback(transferred, key, ov)
  File "D:\Programy\Python\Python36\lib\asyncio\windows_events.py", line 514, in finish_connect
    ov.getresult()
ConnectionRefusedError: [WinError 1225] The remote computer refused the network connection

I'm at a loss as to what I could do to fix this... when I tried using the default asyncio event loop instead, it worked just fine.

Thanks a lot for any help.

altendky commented 6 years ago

I'll note that in Linux I got the desired exception? printed out.

 ⚙  ~/misc/expe/argoneus   master  python3.6 -m venv venv
~/misc/expe/argoneus   master  venv/bin/pip install quamash pyqt5
Collecting quamash
  Downloading Quamash-0.6.0-py3-none-any.whl
Collecting pyqt5
  Using cached PyQt5-5.10.1-5.10.1-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl
Collecting sip<4.20,>=4.19.4 (from pyqt5)
  Using cached sip-4.19.8-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: quamash, sip, pyqt5
Successfully installed pyqt5-5.10.1 quamash-0.6.0 sip-4.19.8
You are using pip version 9.0.1, however version 9.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
 ~/misc/expe/argoneus   master  venv/bin/python t.py
exception?

I get the same result as @argoneuscze in Windows.

PS C:\epc\t\812\testy> py -3.6 -m venv venv
PS C:\epc\t\812\testy> venv\scripts\pip install quamash pyqt5
Collecting quamash
  Downloading Quamash-0.6.0-py3-none-any.whl
Collecting pyqt5
  Using cached PyQt5-5.10.1-5.10.1-cp35.cp36.cp37.cp38-none-win_amd64.whl
Collecting sip<4.20,>=4.19.4 (from pyqt5)
  Using cached sip-4.19.8-cp36-none-win_amd64.whl
Installing collected packages: quamash, sip, pyqt5
Successfully installed pyqt5-5.10.1 quamash-0.6.0 sip-4.19.8
You are using pip version 9.0.1, however version 9.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
PS C:\epc\t\812\testy> venv\scripts\python t.py
Event callback failed
Traceback (most recent call last):
  File "C:\epc\t\812\testy\venv\lib\site-packages\quamash\_windows.py", line 42, in _process_events
    value = callback(transferred, key, ov)
  File "C:\Program Files\Python36\lib\asyncio\windows_events.py", line 514, in finish_connect
    ov.getresult()
ConnectionRefusedError: [WinError 1225] The remote computer refused the network connection

Note that the program hung and did not return to the prompt.

Insoleet commented 6 years ago

On Windows, Quamash uses IOCPProactorLoop. See issue : https://github.com/harvimt/quamash/issues/45