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

Skip to content

Commit 54c950f

Browse files
author
Hirokazu Yamamoto
committed
Issue #9978: Wait until subprocess completes initialization. (Win32KillTests in test_os)
1 parent bc95973 commit 54c950f

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

Lib/test/test_os.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import shutil
1414
from test import support
1515
import contextlib
16+
import mmap
17+
import uuid
1618

1719
# Detect whether we're on a Linux system that uses the (now outdated
1820
# and unmaintained) linuxthreads threading library. There's an issue
@@ -1029,13 +1031,23 @@ def test_kill_int(self):
10291031
self._kill(100)
10301032

10311033
def _kill_with_event(self, event, name):
1034+
tagname = "test_os_%s" % uuid.uuid1()
1035+
m = mmap.mmap(-1, 1, tagname)
1036+
m[0] = 0
10321037
# Run a script which has console control handling enabled.
10331038
proc = subprocess.Popen([sys.executable,
10341039
os.path.join(os.path.dirname(__file__),
1035-
"win_console_handler.py")],
1040+
"win_console_handler.py"), tagname],
10361041
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
10371042
# Let the interpreter startup before we send signals. See #3137.
1038-
time.sleep(0.5)
1043+
count, max = 0, 20
1044+
while count < max and proc.poll() is None:
1045+
if m[0] == 0:
1046+
break
1047+
time.sleep(0.5)
1048+
count += 1
1049+
else:
1050+
self.fail("Subprocess didn't finish initialization")
10391051
os.kill(proc.pid, event)
10401052
# proc.send_signal(event) could also be done here.
10411053
# Allow time for the signal to be passed and the process to exit.

Lib/test/win_console_handler.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from ctypes import wintypes, WINFUNCTYPE
1212
import signal
1313
import ctypes
14+
import mmap
15+
import sys
1416

1517
# Function prototype for the handler function. Returns BOOL, takes a DWORD.
1618
HandlerRoutine = WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD)
@@ -38,6 +40,10 @@ def _ctrl_handler(sig):
3840
print("Unable to add SetConsoleCtrlHandler")
3941
exit(-1)
4042

43+
# Awaken mail process
44+
m = mmap.mmap(-1, 1, sys.argv[1])
45+
m[0] = 1
46+
4147
# Do nothing but wait for the signal
4248
while True:
4349
pass

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ Tools/Demos
311311
Tests
312312
-----
313313

314+
- Issue #9978: Wait until subprocess completes initialization. (Win32KillTests
315+
in test_os)
316+
314317
- Issue #7110: regrtest now sends test failure reports and single-failure
315318
tracebacks to stderr rather than stdout.
316319

0 commit comments

Comments
 (0)