-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
gh-137335: Fix unlikely name conflicts for named pipes in multiprocessing and asyncio on Windows #137389
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
base: main
Are you sure you want to change the base?
gh-137335: Fix unlikely name conflicts for named pipes in multiprocessing and asyncio on Windows #137389
Changes from all commits
2a0a5e9
5b91a56
ed050a0
7363c99
5243b9e
81cb66e
5207bf6
cae80b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,6 @@ | |
| import msvcrt | ||
| import os | ||
| import subprocess | ||
| import tempfile | ||
| import warnings | ||
|
|
||
|
|
||
|
|
@@ -24,17 +23,14 @@ | |
| PIPE = subprocess.PIPE | ||
| STDOUT = subprocess.STDOUT | ||
| _mmap_counter = itertools.count() | ||
| _MAX_PIPE_ATTEMPTS = 100 | ||
|
|
||
|
|
||
| # Replacement for os.pipe() using handles instead of fds | ||
|
|
||
|
|
||
| def pipe(*, duplex=False, overlapped=(True, True), bufsize=BUFSIZE): | ||
| """Like os.pipe() but with overlapped support and using handles not fds.""" | ||
| address = tempfile.mktemp( | ||
| prefix=r'\\.\pipe\python-pipe-{:d}-{:d}-'.format( | ||
| os.getpid(), next(_mmap_counter))) | ||
|
|
||
| if duplex: | ||
| openmode = _winapi.PIPE_ACCESS_DUPLEX | ||
| access = _winapi.GENERIC_READ | _winapi.GENERIC_WRITE | ||
|
|
@@ -56,9 +52,20 @@ def pipe(*, duplex=False, overlapped=(True, True), bufsize=BUFSIZE): | |
|
|
||
| h1 = h2 = None | ||
| try: | ||
| h1 = _winapi.CreateNamedPipe( | ||
| address, openmode, _winapi.PIPE_WAIT, | ||
| 1, obsize, ibsize, _winapi.NMPWAIT_WAIT_FOREVER, _winapi.NULL) | ||
| for attempts in itertools.count(): | ||
| address = r'\\.\pipe\python-pipe-{:d}-{:d}-{}'.format( | ||
| os.getpid(), next(_mmap_counter), os.urandom(8).hex()) | ||
| try: | ||
| h1 = _winapi.CreateNamedPipe( | ||
| address, openmode, _winapi.PIPE_WAIT, | ||
| 1, obsize, ibsize, _winapi.NMPWAIT_WAIT_FOREVER, _winapi.NULL) | ||
| break | ||
| except OSError as e: | ||
| if attempts >= _MAX_PIPE_ATTEMPTS: | ||
| raise | ||
| if e.winerror not in (_winapi.ERROR_PIPE_BUSY, | ||
| _winapi.ERROR_ACCESS_DENIED): | ||
|
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. an infinite loop retrying on this error could potentially hide an error if the system simply doesn't allow this process to create a pipe with the given address? (here and below)
Member
Author
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. I do not know if this is even possible ( |
||
| raise | ||
|
|
||
| h2 = _winapi.CreateFile( | ||
| address, access, 0, _winapi.NULL, _winapi.OPEN_EXISTING, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Get rid of any possibility of a name conflict for named pipes in | ||
| :mod:`multiprocessing` and :mod:`asyncio` on Windows, no matter how small. |
Uh oh!
There was an error while loading. Please reload this page.