-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
There was a problem hiding this 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!
4f9e98e
to
6fc88a5
Compare
def test_seconds(self): | ||
"""L{seconds} should return a plausible epoch time.""" | ||
if hasWindowsSelectorEventLoopPolicy: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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
9b5699d
to
770dd0a
Compare
770dd0a
to
7caf753
Compare
7caf753
to
d78996d
Compare
@adiroiban can you have another look? I don't think that many people are using Twisted with Python's asyncio, because:
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. |
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. |
This PR affects a reactor implementation. Reactor implementations typically have been implemented in the core of Twisted, not outside. |
d78996d
to
9d86143
Compare
@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? |
There was a problem hiding this 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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up ticket: https://twistedmatrix.com/trac/ticket/9966
@@ -32,4 +32,3 @@ jobs: | |||
platform: windows | |||
pythonVersion: ${{ pyver.value }} | |||
windowsReactor: ${{ parameters.reactor }} | |||
allowFailure: ${{ eq(pyver.value, '3.8') }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
9d86143
to
ea1ff17
Compare
@altendky I incorporated your review feedback |
ea1ff17
to
df96b4b
Compare
…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.
df96b4b
to
a3d9e3e
Compare
There was a problem hiding this 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") |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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.