Skip to content

Commit 749a6a8

Browse files
committed
Issue python#23485: Fix test_signal, select.select() now retries the syscall if the
signal handler does not raise an exception
1 parent 9b16666 commit 749a6a8

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

Lib/test/test_signal.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,20 @@ def test_wakeup_fd_early(self):
418418
TIMEOUT_FULL = 10
419419
TIMEOUT_HALF = 5
420420
421+
class InterruptSelect(Exception):
422+
pass
423+
424+
def handler(signum, frame):
425+
raise InterruptSelect
426+
signal.signal(signal.SIGALRM, handler)
427+
421428
signal.alarm(1)
422429
423430
# We attempt to get a signal during the sleep,
424431
# before select is called
425432
try:
426433
select.select([], [], [], TIMEOUT_FULL)
427-
except InterruptedError:
434+
except InterruptSelect:
428435
pass
429436
else:
430437
raise Exception("select() was not interrupted")
@@ -445,15 +452,22 @@ def test_wakeup_fd_during(self):
445452
TIMEOUT_FULL = 10
446453
TIMEOUT_HALF = 5
447454
455+
class InterruptSelect(Exception):
456+
pass
457+
458+
def handler(signum, frame):
459+
raise InterruptSelect
460+
signal.signal(signal.SIGALRM, handler)
461+
448462
signal.alarm(1)
449463
before_time = time.monotonic()
450464
# We attempt to get a signal during the select call
451465
try:
452466
select.select([read], [], [], TIMEOUT_FULL)
453-
except OSError:
467+
except InterruptSelect:
454468
pass
455469
else:
456-
raise Exception("OSError not raised")
470+
raise Exception("select() was not interrupted")
457471
after_time = time.monotonic()
458472
dt = after_time - before_time
459473
if dt >= TIMEOUT_HALF:

0 commit comments

Comments
 (0)