Opened 16 months ago

Closed 9 months ago

#9766 defect closed fixed (fixed)

asyncioreactor almost certainly broken on Windows with Python 3.8

Reported by: Colin Dunklau Owned by: Craig Rodrigues <rodrigc@…>
Priority: normal Milestone: Python 3.8 Support
Component: core Keywords:
Cc: Branch:
Author:

Description (last modified by Craig Rodrigues)

AsyncioSelectorReactor uses get_event_loop by default, which is nice and convenient and good... except when the policy makes it return a non-SelectorEventLoop.

In bpo-34687, Python 3.8 made ProactorEventLoop the default for Windows , and that link also states:

ProactorEventLoop has the following limitations: The loop.add_reader() and loop.add_writer() methods are not supported.

So when you do try to use AsyncioSelectorReactor on py3.8+win, e.g. in the tests for pytest-twisted, you get a rather befuddling error:

<snip>
  File "c:\projects\pytest-twisted\.tox\py38-asyncioreactor\lib\site-packages\twisted\internet\asyncioreactor.py", line 320, in install
    reactor = AsyncioSelectorReactor(eventloop)
  File "c:\projects\pytest-twisted\.tox\py38-asyncioreactor\lib\site-packages\twisted\internet\asyncioreactor.py", line 69, in __init__
    super().__init__()
  File "c:\projects\pytest-twisted\.tox\py38-asyncioreactor\lib\site-packages\twisted\internet\base.py", line 571, in __init__
    self.installWaker()
  File "c:\projects\pytest-twisted\.tox\py38-asyncioreactor\lib\site-packages\twisted\internet\posixbase.py", line 286, in installWaker
    self.addReader(self.waker)
  File "c:\projects\pytest-twisted\.tox\py38-asyncioreactor\lib\site-packages\twisted\internet\asyncioreactor.py", line 151, in addReader
    self._asyncioEventloop.add_reader(fd, callWithLogger, reader,
  File "C:\Python38-x64\Lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError

So, what to do? I hesitate to call the whole situation a Twisted defect, but I do think Twisted should not break in the face of something that should be detectable. I don't know really know the right way to detect this case... the first thought I had was "just typecheck against asyncio.BaseSelectorEventLoop"... which would work, but is maybe icky.

Change History (8)

comment:1 Changed 16 months ago by Nathaniel J. Smith

Tornado ran into the same issue and started a discussion upstream a few months ago: https://bugs.python.org/issue37373

comment:2 Changed 12 months ago by Craig Rodrigues

Description: modified (diff)

comment:3 Changed 12 months ago by Craig Rodrigues

Keywords: review added

comment:4 Changed 10 months ago by Kyle Altendorf

Keywords: review removed
Owner: set to Craig Rodrigues

Review: https://github.com/twisted/twisted/pull/1338#pullrequestreview-482814527

Just a partial first pass as changes were added mid-review

comment:5 Changed 10 months ago by Craig Rodrigues

Keywords: review added
Owner: Craig Rodrigues deleted

comment:6 Changed 9 months ago by Kyle Altendorf

Keywords: review removed
Owner: set to Craig Rodrigues

comment:7 Changed 9 months ago by Craig Rodrigues

Owner: Craig Rodrigues deleted

comment:8 Changed 9 months ago by Craig Rodrigues <rodrigc@…>

Owner: set to Craig Rodrigues <rodrigc@…>
Resolution: fixed
Status: newclosed

In d8203ca6:

Merge pull request #1338 from twisted/9766-rodrigc-asyncio-selecteventorloop

Author: rodrigc
Reviewer: twm
Fixes: ticket:9766 ticket:9809

Fix AsyncioSelectorReactor on Windows Python 3.8+

Note: See TracTickets for help on using tickets.