当前位置: 首页>>代码示例>>Python>>正文


Python psutil.TimeoutExpired方法代码示例

本文整理汇总了Python中psutil.TimeoutExpired方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.TimeoutExpired方法的具体用法?Python psutil.TimeoutExpired怎么用?Python psutil.TimeoutExpired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在psutil的用法示例。


在下文中一共展示了psutil.TimeoutExpired方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_wait_non_children

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def test_wait_non_children(self):
        # Test wait() against a process which is not our direct
        # child.
        p1, p2 = create_proc_children_pair()
        self.assertRaises(psutil.TimeoutExpired, p1.wait, 0.01)
        self.assertRaises(psutil.TimeoutExpired, p2.wait, 0.01)
        # We also terminate the direct child otherwise the
        # grandchild will hang until the parent is gone.
        p1.terminate()
        p2.terminate()
        ret1 = p1.wait()
        ret2 = p2.wait()
        if POSIX:
            self.assertEqual(ret1, -signal.SIGTERM)
            # For processes which are not our children we're supposed
            # to get None.
            self.assertEqual(ret2, None)
        else:
            self.assertEqual(ret1, signal.SIGTERM)
            self.assertEqual(ret1, signal.SIGTERM) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:test_process.py

示例2: test_wait_timeout_0

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def test_wait_timeout_0(self):
        sproc = get_test_subprocess()
        p = psutil.Process(sproc.pid)
        self.assertRaises(psutil.TimeoutExpired, p.wait, 0)
        p.kill()
        stop_at = time.time() + 2
        while True:
            try:
                code = p.wait(0)
            except psutil.TimeoutExpired:
                if time.time() >= stop_at:
                    raise
            else:
                break
        if POSIX:
            self.assertEqual(code, -signal.SIGKILL)
        else:
            self.assertEqual(code, signal.SIGTERM)
        self.assertFalse(p.is_running()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:21,代码来源:test_process.py

示例3: test_wait_stopped

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def test_wait_stopped(self):
        p = self.spawn_psproc()
        if POSIX:
            # Test waitpid() + WIFSTOPPED and WIFCONTINUED.
            # Note: if a process is stopped it ignores SIGTERM.
            p.send_signal(signal.SIGSTOP)
            self.assertRaises(psutil.TimeoutExpired, p.wait, timeout=0.001)
            p.send_signal(signal.SIGCONT)
            self.assertRaises(psutil.TimeoutExpired, p.wait, timeout=0.001)
            p.send_signal(signal.SIGTERM)
            self.assertEqual(p.wait(), -signal.SIGTERM)
            self.assertEqual(p.wait(), -signal.SIGTERM)
        else:
            p.suspend()
            self.assertRaises(psutil.TimeoutExpired, p.wait, timeout=0.001)
            p.resume()
            self.assertRaises(psutil.TimeoutExpired, p.wait, timeout=0.001)
            p.terminate()
            self.assertEqual(p.wait(), signal.SIGTERM)
            self.assertEqual(p.wait(), signal.SIGTERM) 
开发者ID:giampaolo,项目名称:psutil,代码行数:22,代码来源:test_process.py

示例4: test_wait_non_children

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def test_wait_non_children(self):
        # Test wait() against a process which is not our direct
        # child.
        child, grandchild = self.spawn_children_pair()
        self.assertRaises(psutil.TimeoutExpired, child.wait, 0.01)
        self.assertRaises(psutil.TimeoutExpired, grandchild.wait, 0.01)
        # We also terminate the direct child otherwise the
        # grandchild will hang until the parent is gone.
        child.terminate()
        grandchild.terminate()
        child_ret = child.wait()
        grandchild_ret = grandchild.wait()
        if POSIX:
            self.assertEqual(child_ret, -signal.SIGTERM)
            # For processes which are not our children we're supposed
            # to get None.
            self.assertEqual(grandchild_ret, None)
        else:
            self.assertEqual(child_ret, signal.SIGTERM)
            self.assertEqual(child_ret, signal.SIGTERM) 
开发者ID:giampaolo,项目名称:psutil,代码行数:22,代码来源:test_process.py

示例5: test_wait_timeout_nonblocking

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def test_wait_timeout_nonblocking(self):
        p = self.spawn_psproc()
        self.assertRaises(psutil.TimeoutExpired, p.wait, 0)
        p.kill()
        stop_at = time.time() + GLOBAL_TIMEOUT
        while time.time() < stop_at:
            try:
                code = p.wait(0)
                break
            except psutil.TimeoutExpired:
                pass
        else:
            raise self.fail('timeout')
        if POSIX:
            self.assertEqual(code, -signal.SIGKILL)
        else:
            self.assertEqual(code, signal.SIGTERM)
        self.assertProcessGone(p) 
开发者ID:giampaolo,项目名称:psutil,代码行数:20,代码来源:test_process.py

示例6: preprocessor_fixture

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def preprocessor_fixture():
    helper.reset_db()
    Communicator()
    Logger()
    module_proc = modules.Process(modules.Preprocessor)
    module_proc.start()

    yield module_proc

    root_proc = psutil.Process(module_proc.pid)
    procs = root_proc.children(recursive=True)
    try:
        root_proc.terminate()
        root_proc.wait(10)
        module_proc.join(5)
        for p in procs:
            p.terminate()
            p.wait(10)
    except psutil.TimeoutExpired:
        raise Exception("Module process may not be killed success!")

    helper.reset_db()
    Communicator.reset() 
开发者ID:baidu-security,项目名称:openrasp-iast,代码行数:25,代码来源:conftest.py

示例7: test_launcher

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def test_launcher():
    # proc = multiprocessing.Process(target=Launcher().launch)
    # proc.start()
    # time.sleep(2)
    # module_procs = psutil.Process(proc.pid).children(recursive=True)

    # assert len(module_procs) > 2
    # proc.terminate()
    # proc.join(5)
    # if proc.is_alive():
    #     raise Exception(
    #         "launcher process with pid {} may not be killed success!")

    # time.sleep(Config().get_config("monitor.schedule_interval") * 2)
    # for child in module_procs:
    #     try:
    #         child.wait(5)
    #     except psutil.TimeoutExpired:
    #         assert False

    Communicator.reset() 
开发者ID:baidu-security,项目名称:openrasp-iast,代码行数:23,代码来源:test_launcher.py

示例8: _wait_output

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def _wait_output(popen, is_slow):
    """Returns `True` if we can get output of the command in the
    `settings.wait_command` time.

    Command will be killed if it wasn't finished in the time.

    :type popen: Popen
    :rtype: bool

    """
    proc = Process(popen.pid)
    try:
        proc.wait(settings.wait_slow_command if is_slow
                  else settings.wait_command)
        return True
    except TimeoutExpired:
        for child in proc.children(recursive=True):
            _kill_process(child)
        _kill_process(proc)
        return False 
开发者ID:nvbn,项目名称:thefuck,代码行数:22,代码来源:rerun.py

示例9: BlockOnProcessPID

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def BlockOnProcessPID(self, pid, create_time, timeout=None):
        if pid is None:
            return
        p = None
        try:
            p = self.GetProcessByPID(pid, create_time)
            if p is not None and p.is_running() and p.status not in [psutil.STATUS_ZOMBIE, psutil.STATUS_DEAD]:
                val = p.wait(timeout)
                if val is None:
                    self.logger.debug("Process is terminated ")
                else:
                    self.logger.debug("Process is terminated, possibly by os ")
        except psutil.TimeoutExpired:
            self.logger.info("TimeoutExpired happens")
            if p is not None:
                self.logger.info("kill process")
                self.TerminateProcessTree(pid, create_time)
        except Exception:
            self.logger.debug("Process is terminated for unknown reasons")
            pass
        return 
开发者ID:openweave,项目名称:happy,代码行数:23,代码来源:HappyProcess.py

示例10: _attend_process

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def _attend_process(self, proc, sleeptime):
        """
        Waits on a process for a given time to see if it finishes, returns True
        if it's still running after the given time or False as soon as it 
        returns.

        :param psutil.Popen proc: Process object opened by psutil.Popen()
        :param float sleeptime: Time to wait
        :return bool: True if process is still running; otherwise false
        """
        # print("attend:{}".format(proc.pid))
        try:
            proc.wait(timeout=sleeptime)
        except psutil.TimeoutExpired:
            return True
        return False 
开发者ID:databio,项目名称:pypiper,代码行数:18,代码来源:manager.py

示例11: stop_tasks

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def stop_tasks(self, dr):
        logger.debug(f"""Stop tasks for {dr.dag_id} - {dr.run_id}""")
        for ti in dr.get_task_instances():
            logger.debug(f"""process {ti.dag_id} - {ti.task_id} - {ti.execution_date} - {ti.pid}""")
            if ti.state == State.RUNNING:
                try:
                    process = psutil.Process(ti.pid) if ti.pid else None
                except Exception:
                    logger.debug(f" - cannot find process by PID {ti.pid}")
                    process = None
                ti.set_state(State.FAILED)
                logger.debug(" - set state to FAILED")
                if process:
                    logger.debug(f" - wait for process {ti.pid} to exit")
                    try:
                        process.wait(timeout=TIMEOUT * 2)  # raises psutil.TimeoutExpired if timeout. Makes task fail -> DagRun fails
                    except psutil.TimeoutExpired as e:
                        logger.debug(f" - Done waiting for process {ti.pid} to die") 
开发者ID:Barski-lab,项目名称:cwl-airflow,代码行数:20,代码来源:backend.py

示例12: stop_tasks

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def stop_tasks(dr):
    logger.debug(f"""Stop tasks for {dr.dag_id} - {dr.run_id}""")
    for ti in dr.get_task_instances():
        logger.debug(f"""process {ti.dag_id} - {ti.task_id} - {ti.execution_date} - {ti.pid}""")
        if ti.state == State.RUNNING:
            try:
                process = psutil.Process(ti.pid) if ti.pid else None
            except Exception:
                logger.debug(f" - cannot find process by PID {ti.pid}")
                process = None
            ti.set_state(State.FAILED)
            logger.debug(" - set state to FAILED")
            if process:
                logger.debug(f" - wait for process {ti.pid} to exit")
                try:
                    process.wait(timeout=TIMEOUT * 2)  # raises psutil.TimeoutExpired if timeout. Makes task fail -> DagRun fails
                except psutil.TimeoutExpired as e:
                    logger.debug(f" - Done waiting for process {ti.pid} to die") 
开发者ID:Barski-lab,项目名称:cwl-airflow,代码行数:20,代码来源:clean_dag_run.py

示例13: terminate

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def terminate(self):
        # return codes:
        # 0   no work to do
        # 1   terminated
        # -1  failed to terminate

        if not self.pid or not self.isrunning():
            return 0

        timeout = 20

        try:
            proc = psutil.Process(self.pid)
            proc.terminate()
            try:
                proc.wait(timeout=timeout/2)
            except psutil.TimeoutExpired:
                proc.kill()
                proc.wait(timeout=timeout/2)
        except psutil.Error:
            return -1

        return 1 
开发者ID:pytest-dev,项目名称:pytest-xprocess,代码行数:25,代码来源:xprocess.py

示例14: exists

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def exists(pid, time, delta_seconds=3, zombie_seconds=10):
    if not ps.pid_exists(pid):
        log.debug(f'Process {pid} does not exist')
        return False
    process = ps.Process(pid)
    if process.status() == ps.STATUS_ZOMBIE:
        try:
            log.warning(f'Waiting for zombie {pid}')
            process.wait(zombie_seconds)
        except ps.TimeoutExpired:
            log.debug(f'Timeout waiting for zombie {pid}')
        return False
    elif delta_seconds:
        creation_ok = abs(process.create_time() - time.timestamp()) < delta_seconds
        if creation_ok:
            log.debug(f'Process {pid} still exists')
        else:
            log.debug(f'Creation time for process {pid} incorrect ({process.create_time()} / {time.timestamp()})')
        return creation_ok
    else:
        log.debug(f'Assuming process {pid} is same as expected')
        return True   # if delta_seconds = 0 don't check, just assume same 
开发者ID:andrewcooke,项目名称:choochoo,代码行数:24,代码来源:system.py

示例15: kill_process

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import TimeoutExpired [as 别名]
def kill_process(process):
    """Kill a single process.

    Args:
        process (psutil.Process): process to kill.
    """
    if not process.is_running():
        return

    process.kill()

    try:
        process.wait(PROCESS_TERMINATION_TIMEOUT)

    except psutil.TimeoutExpired:
        core_log.warning("Process %d failed to terminate", process.pid) 
开发者ID:gregoil,项目名称:rotest,代码行数:18,代码来源:common.py


注:本文中的psutil.TimeoutExpired方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。