Ejemplo n.º 1
0
 def test_wait_for_exit_raise_disabled(self):
     skip_if_twisted()
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, '-c', 'import sys; sys.exit(1)'])
     ret = yield subproc.wait_for_exit(raise_error=False)
     self.assertEqual(ret, 1)
 def test_sigchild_signal(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess(
         [sys.executable, "-c", "import time; time.sleep(30)"],
         stdout=Subprocess.STREAM,
     )
     self.addCleanup(subproc.stdout.close)
     subproc.set_exit_callback(self.stop)
     os.kill(subproc.pid, signal.SIGTERM)
     try:
         ret = self.wait(timeout=1.0)
     except AssertionError:
         # We failed to get the termination signal. This test is
         # occasionally flaky on pypy, so try to get a little more
         # information: did the process close its stdout
         # (indicating that the problem is in the parent process's
         # signal handling) or did the child process somehow fail
         # to terminate?
         fut = subproc.stdout.read_until_close()
         fut.add_done_callback(lambda f: self.stop())  # type: ignore
         try:
             self.wait(timeout=1.0)
         except AssertionError:
             raise AssertionError("subprocess failed to terminate")
         else:
             raise AssertionError("subprocess closed stdout but failed to "
                                  "get termination signal")
     self.assertEqual(subproc.returncode, ret)
     self.assertEqual(ret, -signal.SIGTERM)
 def test_sigchild_future(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "pass"])
     ret = yield subproc.wait_for_exit()
     self.assertEqual(ret, 0)
     self.assertEqual(subproc.returncode, ret)
 def test_wait_for_exit_raise(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "import sys; sys.exit(1)"])
     with self.assertRaises(subprocess.CalledProcessError) as cm:
         yield subproc.wait_for_exit()
     self.assertEqual(cm.exception.returncode, 1)
Ejemplo n.º 5
0
 def test_wait_for_exit_raise(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "import sys; sys.exit(1)"])
     with self.assertRaises(subprocess.CalledProcessError) as cm:
         yield subproc.wait_for_exit()
     self.assertEqual(cm.exception.returncode, 1)
Ejemplo n.º 6
0
 def test_sigchild_future(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "pass"])
     ret = yield subproc.wait_for_exit()
     self.assertEqual(ret, 0)
     self.assertEqual(subproc.returncode, ret)
Ejemplo n.º 7
0
 def test_sigchild_signal(self):
     skip_if_twisted()
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, '-c',
                           'import time; time.sleep(30)'],
                          stdout=Subprocess.STREAM)
     self.addCleanup(subproc.stdout.close)
     subproc.set_exit_callback(self.stop)
     os.kill(subproc.pid, signal.SIGTERM)
     try:
         ret = self.wait(timeout=1.0)
     except AssertionError:
         # We failed to get the termination signal. This test is
         # occasionally flaky on pypy, so try to get a little more
         # information: did the process close its stdout
         # (indicating that the problem is in the parent process's
         # signal handling) or did the child process somehow fail
         # to terminate?
         subproc.stdout.read_until_close(callback=self.stop)
         try:
             self.wait(timeout=1.0)
         except AssertionError:
             raise AssertionError("subprocess failed to terminate")
         else:
             raise AssertionError("subprocess closed stdout but failed to "
                                  "get termination signal")
     self.assertEqual(subproc.returncode, ret)
     self.assertEqual(ret, -signal.SIGTERM)
Ejemplo n.º 8
0
 def test_wait_for_exit_raise_disabled(self):
     skip_if_twisted()
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, '-c', 'import sys; sys.exit(1)'])
     ret = yield subproc.wait_for_exit(raise_error=False)
     self.assertEqual(ret, 1)
Ejemplo n.º 9
0
 def test_sigchild_future(self):
     skip_if_twisted()
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, '-c', 'pass'])
     ret = yield subproc.wait_for_exit()
     self.assertEqual(ret, 0)
     self.assertEqual(subproc.returncode, ret)
Ejemplo n.º 10
0
 def test_sigchild_future(self):
     skip_if_twisted()
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, '-c', 'pass'])
     ret = yield subproc.wait_for_exit()
     self.assertEqual(ret, 0)
     self.assertEqual(subproc.returncode, ret)
 def test_sigchild(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "pass"])
     subproc.set_exit_callback(self.stop)
     ret = self.wait()
     self.assertEqual(ret, 0)
     self.assertEqual(subproc.returncode, ret)
Ejemplo n.º 12
0
 def test_sigchild(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "pass"])
     subproc.set_exit_callback(self.stop)
     ret = self.wait()
     self.assertEqual(ret, 0)
     self.assertEqual(subproc.returncode, ret)
Ejemplo n.º 13
0
 def test_sigchild_signal(self):
     skip_if_twisted()
     Subprocess.initialize(io_loop=self.io_loop)
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "import time; time.sleep(30)"], io_loop=self.io_loop)
     subproc.set_exit_callback(self.stop)
     os.kill(subproc.pid, signal.SIGTERM)
     ret = self.wait()
     self.assertEqual(subproc.returncode, ret)
     self.assertEqual(ret, -signal.SIGTERM)
Ejemplo n.º 14
0
 def test_sigchild(self):
     # Twisted's SIGCHLD handler and Subprocess's conflict with each other.
     skip_if_twisted()
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, '-c', 'pass'])
     subproc.set_exit_callback(self.stop)
     ret = self.wait()
     self.assertEqual(ret, 0)
     self.assertEqual(subproc.returncode, ret)
Ejemplo n.º 15
0
 def test_sigchild(self):
     # Twisted's SIGCHLD handler and Subprocess's conflict with each other.
     skip_if_twisted()
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, '-c', 'pass'])
     subproc.set_exit_callback(self.stop)
     ret = self.wait()
     self.assertEqual(ret, 0)
     self.assertEqual(subproc.returncode, ret)
Ejemplo n.º 16
0
 def test_sigchild_signal(self):
     Subprocess.initialize(io_loop=self.io_loop)
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, '-c',
                           'import time; time.sleep(30)'],
                          io_loop=self.io_loop)
     subproc.set_exit_callback(self.stop)
     os.kill(subproc.pid, signal.SIGTERM)
     ret = self.wait()
     self.assertEqual(subproc.returncode, ret)
     self.assertEqual(ret, -signal.SIGTERM)
Ejemplo n.º 17
0
def global_signal_master(signals=SIG_TERM_DEFAULT):
    global GLOBAL_SIGNAL_REGISTER

    # `SIGCHLD` signal will handle by tornado.process.Subprocess, this make it as Supervisor of all it's instances.
    Subprocess.initialize()

    for sig_name in list(signals):
        signum = SIG_FROM_NAME[sig_name]
        GLOBAL_SIGNAL_REGISTER[sig_name] = signal.signal(
            signum, global_signal_handler)

    logger.info('Global Safe Signal Register, tid:%s, pid:%s, dask:%s',
                threading.get_ident(), os.getpid(), IN_DASK)
Ejemplo n.º 18
0
    def test_sigchild_signal(self):
        Subprocess.initialize()
        self.addCleanup(Subprocess.uninitialize)
        subproc = Subprocess(
            [sys.executable, "-c", "import time; time.sleep(30)"],
            stdout=Subprocess.STREAM,
        )
        self.addCleanup(subproc.stdout.close)
        subproc.set_exit_callback(self.stop)

        # For unclear reasons, killing a process too soon after
        # creating it can result in an exit status corresponding to
        # SIGKILL instead of the actual signal involved. This has been
        # observed on macOS 10.15 with Python 3.8 installed via brew,
        # but not with the system-installed Python 3.7.
        time.sleep(0.1)

        os.kill(subproc.pid, signal.SIGTERM)
        try:
            ret = self.wait()
        except AssertionError:
            # We failed to get the termination signal. This test is
            # occasionally flaky on pypy, so try to get a little more
            # information: did the process close its stdout
            # (indicating that the problem is in the parent process's
            # signal handling) or did the child process somehow fail
            # to terminate?
            fut = subproc.stdout.read_until_close()
            fut.add_done_callback(lambda f: self.stop())  # type: ignore
            try:
                self.wait()
            except AssertionError:
                raise AssertionError("subprocess failed to terminate")
            else:
                raise AssertionError(
                    "subprocess closed stdout but failed to " "get termination signal"
                )
        self.assertEqual(subproc.returncode, ret)
        self.assertEqual(ret, -signal.SIGTERM)
 def test_wait_for_exit_raise_disabled(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "import sys; sys.exit(1)"])
     ret = yield subproc.wait_for_exit(raise_error=False)
     self.assertEqual(ret, 1)
Ejemplo n.º 20
0
 def test_wait_for_exit_raise_disabled(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "import sys; sys.exit(1)"])
     ret = yield subproc.wait_for_exit(raise_error=False)
     self.assertEqual(ret, 1)