MCPcopy
hub / github.com/tornadoweb/tornado / test_sigchild_signal

Method test_sigchild_signal

tornado/test/process_test.py:209–247  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

207 self.assertEqual(subproc.returncode, ret)
208
209 def test_sigchild_signal(self):
210 Subprocess.initialize()
211 self.addCleanup(Subprocess.uninitialize)
212 subproc = Subprocess(
213 [sys.executable, "-c", "import time; time.sleep(30)"],
214 stdout=Subprocess.STREAM,
215 )
216 self.addCleanup(subproc.stdout.close)
217 subproc.set_exit_callback(self.stop)
218
219 # For unclear reasons, killing a process too soon after
220 # creating it can result in an exit status corresponding to
221 # SIGKILL instead of the actual signal involved. This has been
222 # observed on macOS 10.15 with Python 3.8 installed via brew,
223 # but not with the system-installed Python 3.7.
224 time.sleep(0.1)
225
226 os.kill(subproc.pid, signal.SIGTERM)
227 try:
228 ret = self.wait()
229 except AssertionError:
230 # We failed to get the termination signal. This test is
231 # occasionally flaky on pypy, so try to get a little more
232 # information: did the process close its stdout
233 # (indicating that the problem is in the parent process's
234 # signal handling) or did the child process somehow fail
235 # to terminate?
236 fut = subproc.stdout.read_until_close()
237 fut.add_done_callback(lambda f: self.stop()) # type: ignore
238 try:
239 self.wait()
240 except AssertionError:
241 raise AssertionError("subprocess failed to terminate")
242 else:
243 raise AssertionError(
244 "subprocess closed stdout but failed to " "get termination signal"
245 )
246 self.assertEqual(subproc.returncode, ret)
247 self.assertEqual(ret, -signal.SIGTERM)
248
249 @gen_test
250 def test_wait_for_exit_raise(self):

Callers

nothing calls this directly

Calls 6

set_exit_callbackMethod · 0.95
SubprocessClass · 0.90
read_until_closeMethod · 0.80
initializeMethod · 0.45
waitMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected