Skip to content

Commit cae80b9

Browse files
Limit the number of attempts.
1 parent 5207bf6 commit cae80b9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Lib/asyncio/windows_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
PIPE = subprocess.PIPE
2424
STDOUT = subprocess.STDOUT
2525
_mmap_counter = itertools.count()
26+
_MAX_PIPE_ATTEMPTS = 100
2627

2728

2829
# Replacement for os.pipe() using handles instead of fds
@@ -51,7 +52,7 @@ def pipe(*, duplex=False, overlapped=(True, True), bufsize=BUFSIZE):
5152

5253
h1 = h2 = None
5354
try:
54-
while True:
55+
for attempts in itertools.count():
5556
address = r'\\.\pipe\python-pipe-{:d}-{:d}-{}'.format(
5657
os.getpid(), next(_mmap_counter), os.urandom(8).hex())
5758
try:
@@ -60,6 +61,8 @@ def pipe(*, duplex=False, overlapped=(True, True), bufsize=BUFSIZE):
6061
1, obsize, ibsize, _winapi.NMPWAIT_WAIT_FOREVER, _winapi.NULL)
6162
break
6263
except OSError as e:
64+
if attempts >= _MAX_PIPE_ATTEMPTS:
65+
raise
6366
if e.winerror not in (_winapi.ERROR_PIPE_BUSY,
6467
_winapi.ERROR_ACCESS_DENIED):
6568
raise

Lib/multiprocessing/connection.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
CONNECTION_TIMEOUT = 20.
4747

4848
_mmap_counter = itertools.count()
49+
_MAX_PIPE_ATTEMPTS = 100
4950

5051
default_family = 'AF_INET'
5152
families = ['AF_INET']
@@ -480,12 +481,14 @@ def __init__(self, address=None, family=None, backlog=1, authkey=None):
480481
if address:
481482
self._listener = PipeListener(address, backlog)
482483
else:
483-
while True:
484+
for attempts in itertools.count():
484485
address = arbitrary_address(family)
485486
try:
486487
self._listener = PipeListener(address, backlog)
487488
break
488489
except OSError as e:
490+
if attempts >= _MAX_PIPE_ATTEMPTS:
491+
raise
489492
if e.winerror not in (_winapi.ERROR_PIPE_BUSY,
490493
_winapi.ERROR_ACCESS_DENIED):
491494
raise
@@ -589,7 +592,7 @@ def Pipe(duplex=True):
589592
access = _winapi.GENERIC_WRITE
590593
obsize, ibsize = 0, BUFSIZE
591594

592-
while True:
595+
for attempts in itertools.count():
593596
address = arbitrary_address('AF_PIPE')
594597
try:
595598
h1 = _winapi.CreateNamedPipe(
@@ -603,6 +606,8 @@ def Pipe(duplex=True):
603606
)
604607
break
605608
except OSError as e:
609+
if attempts >= _MAX_PIPE_ATTEMPTS:
610+
raise
606611
if e.winerror not in (_winapi.ERROR_PIPE_BUSY,
607612
_winapi.ERROR_ACCESS_DENIED):
608613
raise

0 commit comments

Comments
 (0)