Skip to content

Commit ed050a0

Browse files
Do not use os.getpid() and tempfile._get_candidate_names().
1 parent 5b91a56 commit ed050a0

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

Lib/asyncio/windows_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import _winapi
99
import msvcrt
1010
import os
11+
import random
1112
import subprocess
12-
import tempfile
1313
import warnings
1414

1515

@@ -48,12 +48,10 @@ def pipe(*, duplex=False, overlapped=(True, True), bufsize=BUFSIZE):
4848
else:
4949
flags_and_attribs = 0
5050

51-
prefix = fr'\\.\pipe\python-pipe-{os.getpid()}-'
52-
names = tempfile._get_candidate_names()
5351
h1 = h2 = None
5452
try:
5553
while True:
56-
address = prefix + next(names)
54+
address = r'\\.\pipe\python-pipe-' + random.randbytes(8).hex()
5755
try:
5856
h1 = _winapi.CreateNamedPipe(
5957
address, openmode, _winapi.PIPE_WAIT,

Lib/multiprocessing/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import errno
1313
import io
1414
import os
15+
import random
1516
import sys
1617
import socket
1718
import struct
@@ -75,7 +76,7 @@ def arbitrary_address(family):
7576
elif family == 'AF_UNIX':
7677
return tempfile.mktemp(prefix='sock-', dir=util.get_temp_dir())
7778
elif family == 'AF_PIPE':
78-
return fr'\\.\pipe\pyc-{os.getpid()}-{next(tempfile._get_candidate_names())}'
79+
return r'\\.\pipe\pyc-' + random.randbytes(8).hex()
7980
else:
8081
raise ValueError('unrecognized family')
8182

0 commit comments

Comments
 (0)