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

Fix fds handling after closing + check if loop is closed #59

Closed Insoleet closed 8 years ago

Insoleet commented 8 years ago

So, using aiohttp and quamash made me found a difference between asyncio loops behaviour and quamash loops :

When closing the web application, I had uncritical errors :

Exception ignored in: <generator object ServerHttpProtocol.start at 0x7febb8303410>
Traceback (most recent call last):
  File "/home/inso/.pyenv/versions/sakia-env/lib/python3.5/site-packages/aiohttp/server.py", line 306, in start
  File "/home/inso/.pyenv/versions/3.5.0/lib/python3.5/asyncio/selector_events.py", line 563, in close
  File "/home/inso/.pyenv/versions/sakia-env/lib/python3.5/site-packages/quamash/__init__.py", line 405, in remove_reader
AttributeError: 'NoneType' object has no attribute 'pop'

To compare why this didn't happen with a standard asyncio loop, I checked the difference between quamash. And in asyncio event loops, if the loop is closed, the remove writer and reader and returned ( https://github.com/python/asyncio/blob/39c135baf73762830148236da622787052efba19/asyncio/selector_events.py#L247 ) When the loop is closed, the add writer and reader methods raise RuntimeError ( https://github.com/python/asyncio/blob/39c135baf73762830148236da622787052efba19/asyncio/selector_events.py#L231 )

There is tests in asyncio for these cases : https://github.com/python/asyncio/blob/39c135baf73762830148236da622787052efba19/tests/test_events.py#L1594 https://github.com/python/asyncio/blob/39c135baf73762830148236da622787052efba19/tests/test_events.py#L1606

Also, when we close the loop, if it is closed, we should return immediately like asyncio ( https://github.com/python/asyncio/blob/39c135baf73762830148236da622787052efba19/asyncio/base_events.py#L393 )

harvimt commented 8 years ago

There's some style problems in test_qeventloop.py, and I'll fix them before I release this to PyPI.