Index: Lib/test/test_os.py =================================================================== --- Lib/test/test_os.py (revision 85107) +++ Lib/test/test_os.py (working copy) @@ -13,6 +13,7 @@ import shutil from test import support import contextlib +import mmap # Detect whether we're on a Linux system that uses the (now outdated # and unmaintained) linuxthreads threading library. There's an issue @@ -1029,13 +1030,18 @@ self._kill(100) def _kill_with_event(self, event, name): + tagname = "python-test#test_os#%d" % os.getpid() + m = mmap.mmap(-1, 1, tagname) + m[0] = 0 # Run a script which has console control handling enabled. proc = subprocess.Popen([sys.executable, os.path.join(os.path.dirname(__file__), - "win_console_handler.py")], + "win_console_handler.py"), tagname], creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) # Let the interpreter startup before we send signals. See #3137. - time.sleep(0.5) + while m[0] == 0: + self.assertIsNone(proc.poll(), "subprocess died unexpectedly") + time.sleep(0.5) os.kill(proc.pid, event) # proc.send_signal(event) could also be done here. # Allow time for the signal to be passed and the process to exit. Index: Lib/test/win_console_handler.py =================================================================== --- Lib/test/win_console_handler.py (revision 85107) +++ Lib/test/win_console_handler.py (working copy) @@ -11,9 +11,11 @@ from ctypes import wintypes import signal import ctypes +import mmap +import sys # Function prototype for the handler function. Returns BOOL, takes a DWORD. -HandlerRoutine = wintypes.WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD) +HandlerRoutine = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD) def _ctrl_handler(sig): """Handle a sig event and return 0 to terminate the process""" @@ -38,6 +40,10 @@ print("Unable to add SetConsoleCtrlHandler") exit(-1) + # Awake main process + m = mmap.mmap(-1, 1, sys.argv[1]) + m[0] = 1 + # Do nothing but wait for the signal while True: pass