Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AsyncioSelectorReactor on Windows Python 3.8+ #1338

Merged
merged 6 commits into from
Sep 14, 2020

Conversation

rodrigc
Copy link
Contributor

@rodrigc rodrigc commented Jul 5, 2020

https://twistedmatrix.com/trac/ticket/9766
https://twistedmatrix.com/trac/ticket/9809

twisted.internet.asyncioreactor.AsyncioSelectorReactor has been changed to use asyncio.SelectorEventLoop

if asyncio.get_event_loop() does not return a SelectorEventLoop.
This fixes AsyncioSelectorReactor on Python 3.8+, where
asyncio.get_event_loop() was changed to return a ProactorEventLoop
in bpo-34687. See: python/cpython@37aae9d.

@rodrigc rodrigc requested review from hawkowl and a team July 5, 2020 01:19
Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have never used asyncio but just by reading the documentation this doesn't look right.

I think that Twisted should use the global asyncio event loop instead of creating a separate event loop.
I guess that this is the purpose of test_defaultEventLoopFromGlobalPolicy which now fails.
This PR is green as the test was skipped.
But I think that the test should not be skipped and instead the code should be updated to have it pass.

Now I don't know if Twisted should auto set the selector policy.

Maybe is best to follow the Tornodo example and have each user set its own policy.

Just my feedback... feel free to ignore it.

Thanks!

azure-pipelines/windows_test_jobs.yml Outdated Show resolved Hide resolved
src/twisted/internet/test/test_asyncioreactor.py Outdated Show resolved Hide resolved
src/twisted/internet/asyncioreactor.py Outdated Show resolved Hide resolved
@rodrigc rodrigc force-pushed the 9766-rodrigc-asyncio-selecteventorloop branch 11 times, most recently from 4f9e98e to 6fc88a5 Compare July 7, 2020 09:46
@rodrigc rodrigc requested a review from adiroiban July 7, 2020 10:36
def test_seconds(self):
"""L{seconds} should return a plausible epoch time."""
if hasWindowsSelectorEventLoopPolicy:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that all the tests using _test_reactor should e moved into a separate test case.
And the AsyncioSelectorReactorTests test case can have a setup method in which it will set WindowsSelectorEventLoopPolicy and reset on teardown.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I don't think it's necessary to hold up the PR for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should at least have been a context manager or try/finally since presently it will just not reset the policy for any failing test... plus I'm already going to go copy/paste this stuff over into #1263 just to catch up.

Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good. Thanks!
I left some minor comments.
The final review should be done by someone using asyncio

@rodrigc rodrigc force-pushed the 9766-rodrigc-asyncio-selecteventorloop branch 3 times, most recently from 9b5699d to 770dd0a Compare July 9, 2020 00:09
@rodrigc rodrigc force-pushed the 9766-rodrigc-asyncio-selecteventorloop branch from 770dd0a to 7caf753 Compare July 20, 2020 23:00
@rodrigc rodrigc force-pushed the 9766-rodrigc-asyncio-selecteventorloop branch from 7caf753 to d78996d Compare August 3, 2020 18:28
@rodrigc rodrigc requested a review from adiroiban August 3, 2020 19:21
@rodrigc
Copy link
Contributor Author

rodrigc commented Aug 3, 2020

@adiroiban can you have another look? I don't think that many people are using Twisted with Python's asyncio, because:

  1. Python's asyncio works on Python-3 only, and many Twisted users were on Python 2 for a long time
  2. Python's asyncio has been changing in every Python release

The main intent of this PR is to just keep up with all the changes in Python's asyncio, so that for people who want to use it in Twisted, they will have a better time, especially on Windows.

@adiroiban
Copy link
Member

It looks good to me. But I am not using async io. I can't check things in a real production environment.

If there is no other twisted core developer interested in asyncio I think that is best to move this code outside of twisted/twisted.

@rodrigc
Copy link
Contributor Author

rodrigc commented Aug 3, 2020

This PR affects a reactor implementation. Reactor implementations typically have been implemented in the core of Twisted, not outside.

@rodrigc rodrigc force-pushed the 9766-rodrigc-asyncio-selecteventorloop branch from d78996d to 9d86143 Compare September 5, 2020 00:17
@altendky
Copy link
Member

altendky commented Sep 5, 2020

@rodrigc, what did you change? Given it was a force repush of all the commits, is there some way for me to see the modifications?

Copy link
Member

@altendky altendky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since things are still changing, here's what I've got for now. I can follow up after these points are gone through and other in-work changes are done.

@@ -1186,6 +1188,8 @@ class FakeObject(object):
"""



@skipIf(not FilePath("/dev/tty").exists(), "Platform lacks /dev/tty")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this PR trigger this to be needed? It's not clear to me why it would.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, this test started failing, so I added it to make further progress on this PR.

There have been hundreds of lines of changes in trunk recently, so I have been updating this PR to stay current.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably know why it is needed if it is going to be included?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks odd to me. Those tests mock the open function, so how is it failing? If you have a reference to the failure you saw please file a ticket; there may be something wrong with the suite.

Do the tests still fail without this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/twisted/internet/asyncioreactor.py Outdated Show resolved Hide resolved
src/twisted/internet/asyncioreactor.py Outdated Show resolved Hide resolved
src/twisted/internet/asyncioreactor.py Show resolved Hide resolved
src/twisted/internet/asyncioreactor.py Outdated Show resolved Hide resolved
src/twisted/internet/asyncioreactor.py Outdated Show resolved Hide resolved
src/twisted/internet/test/test_asyncioreactor.py Outdated Show resolved Hide resolved
@@ -32,4 +32,3 @@ jobs:
platform: windows
pythonVersion: ${{ pyver.value }}
windowsReactor: ${{ parameters.reactor }}
allowFailure: ${{ eq(pyver.value, '3.8') }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any benefit in crossing this with PR #1259 and ticket 9809.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a minor one line change which simply removes ignoring failurs on Python 3.8
during Windows CI. It's OK to leave this in here and address ticket 9809 at the same time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there weren't an existing PR addressing the existing ticket, sure. I don't get why it needs to be confused by mixing it in here.

@rodrigc rodrigc force-pushed the 9766-rodrigc-asyncio-selecteventorloop branch from 9d86143 to ea1ff17 Compare September 5, 2020 02:22
@rodrigc
Copy link
Contributor Author

rodrigc commented Sep 5, 2020

@altendky I incorporated your review feedback

@twisted twisted deleted a comment from mthuurne Sep 6, 2020
@rodrigc rodrigc force-pushed the 9766-rodrigc-asyncio-selecteventorloop branch from ea1ff17 to df96b4b Compare September 6, 2020 06:19
…rror if not passed an asyncio.SelectorEventLoop

In Python 3.8+, asyncio.get_event_loop() was changed to return a
asyncio.ProactorEventLoop in bpo-34687, which is incompatible with
AsyncioSelectorReactor.
@rodrigc rodrigc force-pushed the 9766-rodrigc-asyncio-selecteventorloop branch from df96b4b to a3d9e3e Compare September 14, 2020 01:47
@twm twm mentioned this pull request Sep 14, 2020
5 tasks
Copy link
Contributor

@twm twm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fill in the missing docstring. Otherwise this looks okay to me, with the caveat that I am assuming the problem description to be correct as I know nothing of Windowsland.

@@ -1186,6 +1188,8 @@ class FakeObject(object):
"""



@skipIf(not FilePath("/dev/tty").exists(), "Platform lacks /dev/tty")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks odd to me. Those tests mock the open function, so how is it failing? If you have a reference to the failure you saw please file a ticket; there may be something wrong with the suite.

Do the tests still fail without this change?

def test_seconds(self):
"""L{seconds} should return a plausible epoch time."""
if hasWindowsSelectorEventLoopPolicy:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I don't think it's necessary to hold up the PR for this.

Copy link
Contributor

@twm twm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants