Skip to content

Commit 5207bf6

Browse files
Restore the PID and sequential number for debugging and reducing chance of unintentional conflicts.
1 parent 81cb66e commit 5207bf6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Lib/asyncio/windows_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
raise ImportError('win32 only')
77

88
import _winapi
9+
import itertools
910
import msvcrt
1011
import os
1112
import subprocess
@@ -21,6 +22,7 @@
2122
BUFSIZE = 8192
2223
PIPE = subprocess.PIPE
2324
STDOUT = subprocess.STDOUT
25+
_mmap_counter = itertools.count()
2426

2527

2628
# Replacement for os.pipe() using handles instead of fds
@@ -50,7 +52,8 @@ def pipe(*, duplex=False, overlapped=(True, True), bufsize=BUFSIZE):
5052
h1 = h2 = None
5153
try:
5254
while True:
53-
address = r'\\.\pipe\python-pipe-' + os.urandom(8).hex()
55+
address = r'\\.\pipe\python-pipe-{:d}-{:d}-{}'.format(
56+
os.getpid(), next(_mmap_counter), os.urandom(8).hex())
5457
try:
5558
h1 = _winapi.CreateNamedPipe(
5659
address, openmode, _winapi.PIPE_WAIT,

Lib/multiprocessing/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import errno
1313
import io
14+
import itertools
1415
import os
1516
import sys
1617
import socket
@@ -44,6 +45,8 @@
4445
# A very generous timeout when it comes to local connections...
4546
CONNECTION_TIMEOUT = 20.
4647

48+
_mmap_counter = itertools.count()
49+
4750
default_family = 'AF_INET'
4851
families = ['AF_INET']
4952

@@ -75,7 +78,8 @@ def arbitrary_address(family):
7578
elif family == 'AF_UNIX':
7679
return tempfile.mktemp(prefix='sock-', dir=util.get_temp_dir())
7780
elif family == 'AF_PIPE':
78-
return r'\\.\pipe\pyc-' + os.urandom(8).hex()
81+
return (r'\\.\pipe\pyc-%d-%d-%s' %
82+
(os.getpid(), next(_mmap_counter), os.urandom(8).hex()))
7983
else:
8084
raise ValueError('unrecognized family')
8185

0 commit comments

Comments
 (0)