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


Python psutil.NoSuchProcess方法代码示例

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


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

示例1: __init__

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def __init__(self, pid, idle_limit=None, memory_limit=None, time_limit=None):
        self.limit = {"idle":idle_limit,
                      "memory":memory_limit,
                      "time":time_limit}
        self.check = {"idle":0,
                      "memory":0,
                      "time":0}
        self.idle_start = None
        try:
            if isinstance(pid, psutil.Process):
                self.ps = pid
            else:
                self.ps = psutil.Process(pid)
            self.ps.get_cpu_percent(interval=0)
        except psutil.NoSuchProcess:
            self.ps = None 
开发者ID:blackberry,项目名称:ALF,代码行数:18,代码来源:_common.py

示例2: check_idle

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def check_idle(self):
        now = prof_timer()
        if self.limit["idle"] and self.ps and (now - self.check["idle"]) > self.IDLE_CHECK:
            self.check["idle"] = now
            try:
                cpu_time = self.ps.get_cpu_percent(interval=0) # target cpu usage
                for child in self.ps.get_children(recursive=True):
                    try:
                        c_cpu = child.get_cpu_percent(interval=0)
                        if c_cpu > cpu_time:
                            cpu_time = c_cpu
                    except psutil.NoSuchProcess:
                        pass
            except psutil.NoSuchProcess:
                return False
            if cpu_time < self.IDLE_THRESHOLD:
                if self.idle_start and (now - self.idle_start) > self.limit["idle"]:
                    return True
                if self.idle_start is None:
                    self.idle_start = now
            else:
                self.idle_start = None
        return False 
开发者ID:blackberry,项目名称:ALF,代码行数:25,代码来源:_common.py

示例3: check_memory

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def check_memory(self):
        now = prof_timer()
        if self.limit["memory"] and self.ps and (now - self.check["memory"]) > self.MEMORY_CHECK:
            self.check["memory"] = now
            try:
                target_mem = self.ps.get_memory_info()[0] # target memory usage
                for child in self.ps.get_children(recursive=True):
                    try:
                        target_mem += child.get_memory_info()[0]
                    except psutil.NoSuchProcess:
                        pass
            except psutil.NoSuchProcess:
                target_mem = 0
            if target_mem > self.limit["memory"]:
                return True
        return False 
开发者ID:blackberry,项目名称:ALF,代码行数:18,代码来源:_common.py

示例4: get_mem_usage

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def get_mem_usage(pid):
    try:
        proc = psutil.Process(pid)
        tmp_val = proc.get_memory_info()[0]
    except psutil.NoSuchProcess:
        tmp_val = 0
    return tmp_val 
开发者ID:blackberry,项目名称:ALF,代码行数:9,代码来源:WinDBGMemoryLimit.py

示例5: check

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def check(self):
        """
        Check that the service is running and consistent with pid file(s).

        Returns True or False.
        """
        # Set of pids (strings) where the command string matches what we are
        # looking for.
        detected_pids = set()

        # Set of pids (strings) that are both running processes and found in
        # pid files.
        consistent_pids = set()

        # Search for running processes that match our command string.
        for proc in psutil.process_iter():
            try:
                if self.cmdstring in proc.name():
                    detected_pids.add(str(proc.pid))

            # We could also get psutil.ZombieProcess or
            # psutil.AccessDenied.  We want those to be logged.
            except psutil.NoSuchProcess:
                pass

        # Search for pid file(s) and check consistency.
        for pidfile in self.pidfiles:
            for path in glob.iglob(pidfile):
                with open(path, 'r') as source:
                    pid = source.read().strip()

                if pid in detected_pids:
                    consistent_pids.add(pid)
                else:
                    # Delete the stale pid file.
                    os.remove(path)

        return len(consistent_pids) > 0 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:40,代码来源:procmon.py

示例6: kill_windows_cassandra_procs

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def kill_windows_cassandra_procs():
    # On Windows, forcefully terminate any leftover previously running cassandra processes. This is a temporary
    # workaround until we can determine the cause of intermittent hung-open tests and file-handles.
    if is_win():
        try:
            import psutil
            for proc in psutil.process_iter():
                try:
                    pinfo = proc.as_dict(attrs=['pid', 'name', 'cmdline'])
                except psutil.NoSuchProcess:
                    pass
                else:
                    if (pinfo['name'] == 'java.exe' and '-Dcassandra' in pinfo['cmdline']):
                        print('Found running cassandra process with pid: ' + str(pinfo['pid']) + '. Killing.')
                        psutil.Process(pinfo['pid']).kill()
        except ImportError:
            logger.debug("WARN: psutil not installed. Cannot detect and kill "
                  "running cassandra processes - you may see cascading dtest failures.") 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:20,代码来源:dtest.py

示例7: check_pidfile

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def check_pidfile(filepath, match_name, endpoint_name):
    """ Helper function to identify possible dead endpoints
    """
    if not os.path.exists(filepath):
        return

    older_pid = int(open(filepath, 'r').read().strip())

    try:
        proc = psutil.Process(older_pid)
        if proc.name() == match_name:
            logger.info("Endpoint is already active")
    except psutil.NoSuchProcess:
        logger.info("A prior Endpoint instance appears to have been terminated without proper cleanup")
        logger.info('''Please cleanup using:
    $ funcx-endpoint stop {}'''.format(endpoint_name)) 
开发者ID:funcx-faas,项目名称:funcX,代码行数:18,代码来源:endpoint.py

示例8: kill_process_tree

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def kill_process_tree(pid, include_parent=True):
    try:
        import psutil
    except ImportError:  # pragma: no cover
        return
    try:
        proc = psutil.Process(pid)
    except psutil.NoSuchProcess:
        return

    plasma_sock_dir = None
    children = proc.children(recursive=True)
    if include_parent:
        children.append(proc)
    for p in children:
        try:
            if 'plasma' in p.name():
                plasma_sock_dir = next((conn.laddr for conn in p.connections('unix')
                                        if 'plasma' in conn.laddr), None)
            p.kill()
        except psutil.NoSuchProcess:  # pragma: no cover
            pass
    if plasma_sock_dir:
        shutil.rmtree(plasma_sock_dir, ignore_errors=True) 
开发者ID:mars-project,项目名称:mars,代码行数:26,代码来源:utils.py

示例9: kill_child_processes

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def kill_child_processes(parent_pid):
    """ Kill all the subprocesses recursively """
    try:
        parent = psutil.Process(parent_pid)
    except psutil.NoSuchProcess:
        return
    children = parent.children(recursive=True)
    print(
        "================================ SHUTTING DOWN CLUSTER ================================"
    )
    for process in children:
        try:
            print("SIGTERM >>> " + " ".join(process.cmdline()[1:]))
        except Exception:
            pass
        process.send_signal(signal.SIGTERM)
        process.wait() 
开发者ID:QuarkChain,项目名称:pyquarkchain,代码行数:19,代码来源:cluster.py

示例10: _get_job_status

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def _get_job_status(self, jobpid, jobhash):
        try:
            jobprocess = psutil.Process(pid=jobpid)

        except psutil.NoSuchProcess:
            return {
                'status': 'DONE',
                'returncode': None
            }

        if hash(jobprocess) != jobhash:
            return {
                'status': 'DONE',
                'returncode': None
            }

        return {
            'status': 'RUNNING'
        } 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:21,代码来源:jobs.py

示例11: runPxTest

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def runPxTest(cmd, testproc, ips, port, proxy):
    global PROXY
    PROXY = proxy

    pipe = subprocess.Popen("cmd /k start /wait /min " + cmd + " --port=" + str(port), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    ret = testproc(ips, port)

    pxproc = psutil.Process(pipe.pid)
    for child in pxproc.children(recursive=True):
        try:
            child.kill()
        except psutil.NoSuchProcess:
            pass
    try:
        pxproc.kill()
    except:
        pass

    time.sleep(0.5)

    return ret 
开发者ID:genotrance,项目名称:px,代码行数:24,代码来源:test.py

示例12: sshdisconnection

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def sshdisconnection(pid):
    """Kill the pid no matter what"""
    try:
        parent = psutil.Process(int(pid))
        for child in parent.children(): 
            child.kill()
        parent.kill()

    except Exception as E:
        if type(E) == psutil.NoSuchProcess:
            app.logger.warning("Impossible to kill: no such process with PID " + str(pid))

    return "Done"


########################
#### FILES DOWNLOAD #### 
开发者ID:LibrIT,项目名称:passhport,代码行数:19,代码来源:views.py

示例13: test_kill_terminate

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def test_kill_terminate(self):
        # subprocess.Popen()'s terminate(), kill() and send_signal() do
        # not raise exception after the process is gone. psutil.Popen
        # diverges from that.
        cmd = [PYTHON_EXE, "-c", "import time; time.sleep(60);"]
        with psutil.Popen(cmd, stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE) as proc:
            proc.terminate()
            proc.wait()
            self.assertRaises(psutil.NoSuchProcess, proc.terminate)
            self.assertRaises(psutil.NoSuchProcess, proc.kill)
            self.assertRaises(psutil.NoSuchProcess, proc.send_signal,
                              signal.SIGTERM)
            if WINDOWS and sys.version_info >= (2, 7):
                self.assertRaises(psutil.NoSuchProcess, proc.send_signal,
                                  signal.CTRL_C_EVENT)
                self.assertRaises(psutil.NoSuchProcess, proc.send_signal,
                                  signal.CTRL_BREAK_EVENT) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:test_process.py

示例14: test_process_iter

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def test_process_iter(self):
        self.assertIn(os.getpid(), [x.pid for x in psutil.process_iter()])
        sproc = get_test_subprocess()
        self.assertIn(sproc.pid, [x.pid for x in psutil.process_iter()])
        p = psutil.Process(sproc.pid)
        p.kill()
        p.wait()
        self.assertNotIn(sproc.pid, [x.pid for x in psutil.process_iter()])

        with mock.patch('psutil.Process',
                        side_effect=psutil.NoSuchProcess(os.getpid())):
            self.assertEqual(list(psutil.process_iter()), [])
        with mock.patch('psutil.Process',
                        side_effect=psutil.AccessDenied(os.getpid())):
            with self.assertRaises(psutil.AccessDenied):
                list(psutil.process_iter()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_system.py

示例15: get_process_ids

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import NoSuchProcess [as 别名]
def get_process_ids(process_id, recursive=True):
  """Return list of pids for a process and its descendants."""
  # Try to find the running process.
  if not psutil.pid_exists(process_id):
    return []

  pids = [process_id]

  try:
    psutil_handle = psutil.Process(process_id)
    children = psutil_handle.children(recursive=recursive)
    for child in children:
      pids.append(child.pid)
  except psutil.NoSuchProcess:
    # Avoid too much logging when the process already died.
    return []

  except (psutil.AccessDenied, OSError):
    logs.log_warn('Failed to get process children.')
    return []

  return pids 
开发者ID:google,项目名称:clusterfuzz,代码行数:24,代码来源:utils.py


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