Skip to content
Prev Previous commit
Next Next commit
Restore the PID and sequential number for debugging and reducing chan…
…ce of unintentional conflicts.
  • Loading branch information
serhiy-storchaka committed Feb 10, 2026
commit 5207bf6dca8dfea4e6cd53fd08c74102d381b8ff
5 changes: 4 additions & 1 deletion Lib/asyncio/windows_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
raise ImportError('win32 only')

import _winapi
import itertools
import msvcrt
import os
import subprocess
Expand All @@ -21,6 +22,7 @@
BUFSIZE = 8192
PIPE = subprocess.PIPE
STDOUT = subprocess.STDOUT
_mmap_counter = itertools.count()


# Replacement for os.pipe() using handles instead of fds
Expand Down Expand Up @@ -50,7 +52,8 @@ def pipe(*, duplex=False, overlapped=(True, True), bufsize=BUFSIZE):
h1 = h2 = None
try:
while True:
address = r'\\.\pipe\python-pipe-' + os.urandom(8).hex()
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,
Expand Down
6 changes: 5 additions & 1 deletion Lib/multiprocessing/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import errno
import io
import itertools
import os
import sys
import socket
Expand Down Expand Up @@ -44,6 +45,8 @@
# A very generous timeout when it comes to local connections...
CONNECTION_TIMEOUT = 20.

_mmap_counter = itertools.count()

default_family = 'AF_INET'
families = ['AF_INET']

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

Expand Down