當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。