Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Use os.urandom().
  • Loading branch information
serhiy-storchaka committed Feb 5, 2026
commit 5243b9ea7790fec7b184056b04fcea0f51a87ed9
3 changes: 1 addition & 2 deletions Lib/asyncio/windows_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import _winapi
import msvcrt
import os
import random
import subprocess
import warnings

Expand Down Expand Up @@ -51,7 +50,7 @@ def pipe(*, duplex=False, overlapped=(True, True), bufsize=BUFSIZE):
h1 = h2 = None
try:
while True:
address = r'\\.\pipe\python-pipe-' + random.randbytes(8).hex()
address = r'\\.\pipe\python-pipe-' + os.urandom(8).hex()
try:
h1 = _winapi.CreateNamedPipe(
address, openmode, _winapi.PIPE_WAIT,
Expand Down
3 changes: 1 addition & 2 deletions Lib/multiprocessing/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import errno
import io
import os
import random
import sys
import socket
import struct
Expand Down Expand Up @@ -76,7 +75,7 @@ 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-' + random.randbytes(8).hex()
return r'\\.\pipe\pyc-' + os.urandom(8).hex()
else:
raise ValueError('unrecognized family')

Expand Down
Loading