Example #1
0
    def kill(self, wait_time=60):
        """Kills or cancels the supplied task

        Sends SIGTERM, waits for a period of <wait_time> for graceful
        termination, then sends a hard kill with SIGKILL.  If <wait_time>
        is 0, we go immediately to SIGKILL; if <wait_time> is none, we
        never do a SIGKILL.
        """
        if self.dry_run:
            return

        if self.finished:
            logger.warning("Trying to kill task that is no longer running. "
                           "Task {}: Status is {}".format(self.name, self.state))
            return

        if self.process is None:
            time.sleep(0.2)
            jassert(self.process is not None,
                    "Attempting to kill task {} that has no process ID - "
                    "check tasks been launched".format(self.name))

        logger.info("Killing task {}".format(self.name))
        launcher.cancel(self.process, wait_time)
        self.state = 'USER_KILLED'
        self.finished = True
        self.calc_task_timing()
Example #2
0
def xtest_submit():
    "Test simple launch."

    py_exe = sys.executable or "python"

    # Launch infinite loop, pay attention to term
    process = launcher.launch([py_exe, "launch_busy.py"])
    assert not launcher.process_is_stopped(process,
                                           0.1), "Process stopped early."
    launcher.cancel(process, 0.5)

    # Launch infinite loop, ignore term
    process = launcher.launch([py_exe, "launch_busy.py", "1"])
    assert not launcher.process_is_stopped(process,
                                           0.5), "Process stopped early."
    launcher.cancel(process, 0.5)

    # Launch infinite loop, pay attention to term
    process = launcher.launch([py_exe, "launch_busy.py"],
                              start_new_session=True)
    assert not launcher.process_is_stopped(process,
                                           0.1), "Process stopped early."
    launcher.cancel(process, 0.5)

    # Launch infinite loop, ignore term
    process = launcher.launch([py_exe, "launch_busy.py", "1"],
                              start_new_session=True)
    assert not launcher.process_is_stopped(process,
                                           0.5), "Process stopped early."
    launcher.cancel(process, 0.5)

    # Check proper handling of ProcessLookupError
    assert not launcher.killpg(process), "Expected lookup error."
    assert not launcher.terminatepg(process), "Expected lookup error."

    # Launch finite loop, wait for termination
    process = launcher.launch([py_exe, "launch_busy.py", "0", "0.1"])
    assert launcher.process_is_stopped(
        process, 1.5), "Process should have stopped earlier."

    # Try simple kill
    process = launcher.launch([py_exe, "launch_busy.py", "1"])
    assert not launcher.process_is_stopped(process,
                                           0.5), "Process stopped early."
    launcher.cancel(process, 0)
Example #3
0
 def cleanup():
     "Handler to clean up launched team."
     for wp in worker_procs:
         launcher.cancel(wp, timeout=libE_specs.get('worker_timeout'))