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

Add support for Named Pipes to Site and Connector under Windows #3632

Closed
wants to merge 15 commits into from

Conversation

hackrush01
Copy link

@hackrush01 hackrush01 commented Feb 28, 2019

What do these changes do?

Adds support for named pipes in windows

Are there changes in behavior for the user?

No

Related issue number

#3629

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@hackrush01 hackrush01 requested a review from asvetlov as a code owner February 28, 2019 19:14
@hackrush01 hackrush01 force-pushed the named-pipes-support branch from 2778d5e to 532ba8b Compare March 1, 2019 06:27
@codecov-io
Copy link

codecov-io commented Mar 1, 2019

Codecov Report

Merging #3632 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3632   +/-   ##
=======================================
  Coverage   97.83%   97.83%           
=======================================
  Files          43       43           
  Lines        8604     8604           
  Branches     1377     1377           
=======================================
  Hits         8418     8418           
  Misses         80       80           
  Partials      106      106

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ffe04cc...e96f6c6. Read the comment docs.

Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

Looks good.
Please

  1. Add ./CHANGES note
  2. Document both connector and runner
  3. Add tests for new classes. Tests should be marked by pytest.mark.skipif() to run on Windows only.

@hackrush01
Copy link
Author

hackrush01 commented Mar 1, 2019 via email

@hackrush01 hackrush01 force-pushed the named-pipes-support branch from 6848e46 to 43999c0 Compare March 2, 2019 18:46
@hackrush01
Copy link
Author

hackrush01 commented Mar 2, 2019

Windows proactor event policy was added only in python 3.7
https://bugs.python.org/issue33792
See last point here
Finding a workaround

@hackrush01 hackrush01 requested a review from webknjaz as a code owner March 3, 2019 13:00
@hackrush01 hackrush01 force-pushed the named-pipes-support branch from ba91ef3 to 7a437be Compare March 3, 2019 14:50
@hackrush01
Copy link
Author

hackrush01 commented Mar 4, 2019

I don't understand what's up with code cov bot
Is it me?

@hackrush01
Copy link
Author

Now it works

@@ -58,7 +57,9 @@ def name(self) -> str:
self._runner._unreg_site(self)
return # not started yet
self._server.close()
await self._server.wait_closed()
# named pipes do not have wait_closed property
Copy link
Member

Choose a reason for hiding this comment

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

So why don't you create one?

Copy link
Author

Choose a reason for hiding this comment

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

Named pipes in asyncio are from the class: https://github.com/python/cpython/blob/master/Lib/asyncio/windows_events.py#L241

Which comprises of only normal sync methods. .close() is a sync method as well. So therefore it has a .closed() property. Are you suggesting to add .wait_closed() property there for consistency(hence a PR to cython)?
Or is it something else?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'd just inherit that and return immediately maybe. Let's see what @asvetlov thinks.

loop = asyncio.get_event_loop()
server = self._runner.server
assert server is not None
_server = await loop.start_serving_pipe( # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

Why ignore the type?

Copy link
Author

Choose a reason for hiding this comment

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

start_serving_pipe is not defined in AbstractEventLoop. So it throws the following

aiohttp\connector.py:1149: error: Invalid type "asyncio.ProactorEventLoop"
aiohttp\connector.py:1166: error: "AbstractEventLoop" has no attribute "create_pipe_connection"; ma
ybe "create_connection" or "create_unix_connection"?

Is there some other way I'm missing?

Copy link
Member

Choose a reason for hiding this comment

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

Dunno. Maybe @asvetlov knows a better way

try:
with CeilTimeout(timeout.sock_connect):
_, proto = \
await self._loop.create_pipe_connection( # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

Why ignore type?

Copy link
Author

Choose a reason for hiding this comment

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

Same reason as above

def __init__(self, path: str, force_close: bool=False,
keepalive_timeout: Union[object, float, None]=sentinel,
limit: int=100, limit_per_host: int=0,
loop: Optional[asyncio.AbstractEventLoop]=None) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
loop: Optional[asyncio.AbstractEventLoop]=None) -> None:
loop: Optional[asyncio.ProactorEventLoop]=None) -> None:

Copy link
Author

Choose a reason for hiding this comment

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

Changing this causes(while running mypy)

aiohttp\connector.py:1149: error: Invalid type "asyncio.ProactorEventLoop"

Copy link
Member

Choose a reason for hiding this comment

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

Odd... are you running mypy under Python 3.7?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could add a conditional for this to work under Linux?

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    try:
        from asyncio import ProactorEventLoop
    except ImportError:
        from asyncio import AbstractEventLoop
        class ProactorEventLoop(ProactorEventLoop):
            """ProactorEventLoop stub for mypy."""

Copy link
Author

Choose a reason for hiding this comment

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

I am infact running mypy under python 3.7.
Also I too tried with

if TYPE_CHECKING:
    from asyncio import ProactorEventLoop

Still the same error.
I'll try again, maybe I did something wrong in rush

Copy link
Author

Choose a reason for hiding this comment

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

Nope, still happening. It is odd

Copy link
Member

Choose a reason for hiding this comment

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

It's because you're trying to make the import under Linux and docs say it's available only under windows

Copy link
Author

Choose a reason for hiding this comment

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

It fails on my computer too, where I'm running it on windows 🤔

Copy link
Author

Choose a reason for hiding this comment

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

Though, what's surprising is that it failes to find ProactorEventLoop during definition
but not when used inside the functions, such as this instance
assert isinstance(self._loop, asyncio.ProactorEventLoop)

Copy link
Member

Choose a reason for hiding this comment

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

attribute access is not static analysis by MyPy

loop - Optional event loop.
"""

def __init__(self, path: str, force_close: bool=False,
Copy link
Member

Choose a reason for hiding this comment

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

You should validate that it runs under ProactorEventLoop somewhere at the beginning of this method, I think.

Copy link
Author

Choose a reason for hiding this comment

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

I thought about it, but creating a NamedPipeConnector, raises
AttributeError: '_WindowsSelectorEventLoop' object has no attribute 'create_pipe_connection'
Wouldn't that be okay?
But if there is no assertion then the error wouldn't be raised when loop.create_pipe_connection() is mocked out. So maybe there is a need for the assertion too.
I'd be fine with whatever seems okay to you.

Copy link
Author

Choose a reason for hiding this comment

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

Also, if we end up adding the assert in this case, we'd be adding it here as well, right?
https://github.com/aio-libs/aiohttp/pull/3632/files#diff-dbf24c78287ef0b964d4945f339a43a9R135

@hackrush01
Copy link
Author

I removed a test in web_runner.py which literally was just testing that the variable was correctly assigned.
Also, everywhere I used asyncio.ProactorEventLoop I had to put # type: ignore because mypy complains

@hackrush01
Copy link
Author

Oy Vey! No way to cancel AppVeyor and Travis Builds...
Sorry for so many commits...
In my defense... Windows is hard :-P

@webknjaz webknjaz changed the title Add support for Named Pipes(Site and Connector) on windows. Add support for Named Pipes to Site and Connector under Windows Mar 5, 2019
@hackrush01 hackrush01 force-pushed the named-pipes-support branch from 263701d to c0ec73e Compare March 7, 2019 18:27
@hackrush01
Copy link
Author

@webknjaz Just checking to be sure we are on the same page; The PR is awaiting comments/review from @asvetlov, right? Because I think I have done all the other non-ambiguous stuff 🤔 .

@eukreign
Copy link

eukreign commented Apr 6, 2019

@asvetlov @webknjaz Is this PR still being considered? Really looking forward to this feature!

@jackrobison
Copy link

@asvetlov I'm really looking forward to using this - what's holding up merging it?

@asvetlov
Copy link
Member

asvetlov commented May 7, 2019

I need time to review the PR carefully.
Sorry, pretty busy now, need to add several features to asyncio before Python 3.8 feature freeze date.

Do you ask for merging only or for publishing a new aiohttp release with windows named pipes functionality implemented?
The first is easy, the second requires more work to be done.

@eukreign
Copy link

eukreign commented May 8, 2019

Ultimately, releasing a new aiohttp with this feature is the most useful thing. Although just merging it would also help in terms of knowing that this is how it will work / what the API will be like, etc, even if we can't really use it yet (until it's on pypi), we can at least start programming against a future release of it.

Would you say that at least the overall API / architecture of this PR is how it will be in the final version?

@asvetlov
Copy link
Member

asvetlov commented May 8, 2019

I'm on the trip now. Will review and merge the PR in a few days

@eukreign
Copy link

eukreign commented May 8, 2019

Awesome, thanks! Have a safe trip.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jul 4, 2019

This pull request introduces 1 alert when merging e96f6c6 into ffe04cc - view on LGTM.com

new alerts:

  • 1 for Module-level cyclic import

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jul 4, 2019

This pull request introduces 1 alert when merging 5739e1e into ffe04cc - view on LGTM.com

new alerts:

  • 1 for Module-level cyclic import

@asvetlov asvetlov closed this in edc7c0f Jul 4, 2019
@asvetlov
Copy link
Member

asvetlov commented Jul 4, 2019

Merged manually

@asvetlov
Copy link
Member

asvetlov commented Jul 4, 2019

Thanks, @eukreign

asvetlov added a commit that referenced this pull request Jul 4, 2019
…der Windows.

(cherry picked from commit edc7c0f)

Co-authored-by: Andrew Svetlov <[email protected]>
asvetlov added a commit that referenced this pull request Jul 5, 2019
…der Windows. (#3885)

(cherry picked from commit edc7c0f)

Co-authored-by: Andrew Svetlov <[email protected]>
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.

6 participants