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

Skip to content

Commit dee0434

Browse files
committed
Fixes issue #15507: test_subprocess's test_send_signal could fail if the test
runner were run in an environment where the process inherited an ignore setting for SIGINT. Restore the SIGINT handler to the desired KeyboardInterrupt raising one during that test.
1 parent e33d5b0 commit dee0434

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

Lib/test/test_subprocess.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,16 +1398,22 @@ def test_specific_shell(self):
13981398
def _kill_process(self, method, *args):
13991399
# Do not inherit file handles from the parent.
14001400
# It should fix failures on some platforms.
1401-
p = subprocess.Popen([sys.executable, "-c", """if 1:
1402-
import sys, time
1403-
sys.stdout.write('x\\n')
1404-
sys.stdout.flush()
1405-
time.sleep(30)
1406-
"""],
1407-
close_fds=True,
1408-
stdin=subprocess.PIPE,
1409-
stdout=subprocess.PIPE,
1410-
stderr=subprocess.PIPE)
1401+
# Also set the SIGINT handler to the default to make sure it's not
1402+
# being ignored (some tests rely on that.)
1403+
old_handler = signal.signal(signal.SIGINT, signal.default_int_handler)
1404+
try:
1405+
p = subprocess.Popen([sys.executable, "-c", """if 1:
1406+
import sys, time
1407+
sys.stdout.write('x\\n')
1408+
sys.stdout.flush()
1409+
time.sleep(30)
1410+
"""],
1411+
close_fds=True,
1412+
stdin=subprocess.PIPE,
1413+
stdout=subprocess.PIPE,
1414+
stderr=subprocess.PIPE)
1415+
finally:
1416+
signal.signal(signal.SIGINT, old_handler)
14111417
# Wait for the interpreter to be completely initialized before
14121418
# sending any signal.
14131419
p.stdout.read(1)

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ IDLE
309309
Tests
310310
-----
311311

312+
- Issue #15507: test_subprocess's test_send_signal could fail if the test
313+
runner were run in an environment where the process inherited an ignore
314+
setting for SIGINT. Restore the SIGINT handler to the desired
315+
KeyboardInterrupt raising one during that test.
316+
312317
- Issue #18792: Use "127.0.0.1" or "::1" instead of "localhost" as much as
313318
possible, since "localhost" goes through a DNS lookup under recent Windows
314319
versions.

0 commit comments

Comments
 (0)