-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix errors with multi-process workers on Windows #22016
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
Open
chadrik
wants to merge
1
commit into
python:master
Choose a base branch
from
chadrik:fix/win-worker-timeout-part1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+52
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,7 +65,8 @@ class IPCBase: | |
|
|
||
| def __init__(self, name: str, timeout: float | None) -> None: | ||
| self.name = name | ||
| self.timeout = timeout | ||
| self.timeout = timeout # Connections | ||
| self.io_timeout = timeout # Reads and writes | ||
| self.message_size: int | None = None | ||
| self.buffer = bytearray() | ||
|
|
||
|
|
@@ -101,7 +102,9 @@ def read_bytes(self, size: int = MAX_READ) -> bytes: | |
| ov, err = _winapi.ReadFile(self.connection, size, overlapped=True) | ||
| try: | ||
| if err == _winapi.ERROR_IO_PENDING: | ||
| timeout = int(self.timeout * 1000) if self.timeout else _winapi.INFINITE | ||
| timeout = ( | ||
| int(self.io_timeout * 1000) if self.io_timeout else _winapi.INFINITE | ||
| ) | ||
| res = _winapi.WaitForSingleObject(ov.event, timeout) | ||
| if res != _winapi.WAIT_OBJECT_0: | ||
| raise IPCException(f"Bad result from I/O wait: {res}") | ||
|
|
@@ -158,7 +161,9 @@ def write_bytes(self, data: bytes) -> None: | |
| ov, err = _winapi.WriteFile(self.connection, encoded_data, overlapped=True) | ||
| try: | ||
| if err == _winapi.ERROR_IO_PENDING: | ||
| timeout = int(self.timeout * 1000) if self.timeout else _winapi.INFINITE | ||
| timeout = ( | ||
| int(self.io_timeout * 1000) if self.io_timeout else _winapi.INFINITE | ||
| ) | ||
| res = _winapi.WaitForSingleObject(ov.event, timeout) | ||
| if res != _winapi.WAIT_OBJECT_0: | ||
| raise IPCException(f"Bad result from I/O wait: {res}") | ||
|
|
@@ -247,6 +252,11 @@ def __init__(self, name: str, timeout: float | None = None) -> None: | |
| else: | ||
| name = f"{name}.sock" | ||
| super().__init__(name, timeout) | ||
| # Unlike the client, a server applies its timeout only to accepting a | ||
| # connection, never to the traffic that follows: see __enter__ below. Once a | ||
| # peer is connected it may legitimately stay silent for a long time while it | ||
| # computes. | ||
| self.io_timeout = None | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two things here: move this under an |
||
| if sys.platform == "win32": | ||
| self.connection = _winapi.CreateNamedPipe( | ||
| self.name, | ||
|
|
@@ -298,6 +308,10 @@ def __enter__(self) -> IPCServer: | |
| assert err == 0 | ||
| else: | ||
| try: | ||
| # Note self.timeout is set on the listening socket in __init__, but this | ||
| # applies to accept() only: the socket returned below is always blocking | ||
| # (see socket.accept()). This is why self.io_timeout is None -- it ensures | ||
| # equivalent behavior between Windows and POSIX. | ||
| self.connection, _ = self.sock.accept() | ||
| # This is already default on Linux, we set same buffer size | ||
| # for macOS vs Linux consistency to simplify reasoning. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 name is a bit misleading. It looks like it would affect POSIX as well. I think it is better to call this
win_io_timeout.