| 86 | |
| 87 | @unittest.skipIf(mmap is None, "requires mmap") |
| 88 | def _kill_with_event(self, event, name): |
| 89 | tagname = "test_os_%s" % uuid.uuid1() |
| 90 | m = mmap.mmap(-1, 1, tagname) |
| 91 | m[0] = 0 |
| 92 | |
| 93 | # Run a script which has console control handling enabled. |
| 94 | script = os.path.join(os.path.dirname(__file__), |
| 95 | "win_console_handler.py") |
| 96 | cmd = [sys.executable, script, tagname] |
| 97 | proc = subprocess.Popen(cmd, |
| 98 | creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) |
| 99 | |
| 100 | with proc: |
| 101 | # Let the interpreter startup before we send signals. See #3137. |
| 102 | for _ in support.sleeping_retry(support.SHORT_TIMEOUT): |
| 103 | if proc.poll() is None: |
| 104 | break |
| 105 | else: |
| 106 | # Forcefully kill the process if we weren't able to signal it. |
| 107 | proc.kill() |
| 108 | self.fail("Subprocess didn't finish initialization") |
| 109 | |
| 110 | os.kill(proc.pid, event) |
| 111 | |
| 112 | try: |
| 113 | # proc.send_signal(event) could also be done here. |
| 114 | # Allow time for the signal to be passed and the process to exit. |
| 115 | proc.wait(timeout=support.SHORT_TIMEOUT) |
| 116 | except subprocess.TimeoutExpired: |
| 117 | # Forcefully kill the process if we weren't able to signal it. |
| 118 | proc.kill() |
| 119 | self.fail("subprocess did not stop on {}".format(name)) |
| 120 | |
| 121 | @unittest.skip("subprocesses aren't inheriting Ctrl+C property") |
| 122 | @support.requires_subprocess() |