當前位置: 首頁>>代碼示例>>Python>>正文


Python psutil.CONN_LISTEN屬性代碼示例

本文整理匯總了Python中psutil.CONN_LISTEN屬性的典型用法代碼示例。如果您正苦於以下問題:Python psutil.CONN_LISTEN屬性的具體用法?Python psutil.CONN_LISTEN怎麽用?Python psutil.CONN_LISTEN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在psutil的用法示例。


在下文中一共展示了psutil.CONN_LISTEN屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_quiet

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import CONN_LISTEN [as 別名]
def test_quiet(kind):
    with TestProcess(sys.executable, __file__, 'daemon', 'test_quiet', kind) as proc:
        with dump_on_error(proc.read):
            wait_for_strings(proc.read, TIMEOUT,
                             '{a1}',
                             '{b1}')
            psproc = psutil.Process(proc.proc.pid)
            port = None
            t = time.time()
            while port is None and time.time() - t < 5:
                for c in psproc.connections():
                    if c.status == psutil.CONN_LISTEN and c.laddr[0] == '127.0.0.1':
                        port = c.laddr[1]

            with TestSocket(socket.create_connection(('127.0.0.1', int(port)), timeout=TIMEOUT)) as client:
                with dump_on_error(client.read):
                    wait_for_strings(client.read, TIMEOUT, "-> print('{b2}')")
                    client.fh.write(b'continue\r\n')
            wait_for_strings(proc.read, TIMEOUT, 'DIED.')
            assert 'RemotePdb session open at' not in proc.read() 
開發者ID:ionelmc,項目名稱:python-remote-pdb,代碼行數:22,代碼來源:test_remote_pdb.py

示例2: check_lnd

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import CONN_LISTEN [as 別名]
def check_lnd(stub, proc_name="lnd", rpc_listen_ports=None):
    if not rpc_listen_ports:
        rpc_listen_ports = [10009]

    pid_ok = False
    listen_ok = False
    unlocked = False
    synced_to_chain = False
    synced_to_graph = False

    if IS_WIN32_ENV:
        return pid_ok, listen_ok, unlocked, synced_to_chain, synced_to_graph

    if not [p.info for p in psutil.process_iter(attrs=['pid', 'name']) if proc_name in p.info['name']]:
        return pid_ok, listen_ok, unlocked, synced_to_chain, synced_to_graph
    else:
        pid_ok = True

    if not [net_con for net_con in psutil.net_connections(kind='inet')
            if (net_con.status == psutil.CONN_LISTEN and net_con.laddr[1] in rpc_listen_ports)]:
        return pid_ok, listen_ok, unlocked, synced_to_chain, synced_to_graph
    else:
        listen_ok = True

    try:
        get_info = stub.GetInfo(ln.GetInfoRequest())
        unlocked = True
        synced_to_chain = get_info.synced_to_chain
        synced_to_graph = get_info.synced_to_graph

    except grpc.RpcError as err:
        if err._state.__dict__['code'] == grpc.StatusCode.UNIMPLEMENTED:
            log.debug("wallet is 'locked'")
        else:
            log.warning("an unknown RpcError occurred")
            log.warning(err)

    except Exception as err:
        log.warning("an error occurred: {}".format(err))

    return pid_ok, listen_ok, unlocked, synced_to_chain, synced_to_graph 
開發者ID:rootzoll,項目名稱:raspiblitz,代碼行數:43,代碼來源:client.py

示例3: _detect_iface_name

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import CONN_LISTEN [as 別名]
def _detect_iface_name(self, h_ipdb):
        # Let's try config first
        if config.CONF.binding.link_iface in h_ipdb.interfaces:
            LOG.debug(f'Using configured interface '
                      f'{config.CONF.binding.link_iface} as bridge interface.')
            return config.CONF.binding.link_iface

        # Then let's try choosing the one where kubelet listens to
        conns = [x for x in psutil.net_connections()
                 if x.status == psutil.CONN_LISTEN
                 and x.laddr.port == KUBELET_PORT]
        if len(conns) == 1:
            lookup_addr = conns[0].laddr.ip
            for name, iface in h_ipdb.interfaces.items():
                if type(name) is int:  # Skip ones duplicated by id
                    continue

                for addr in iface['ipaddr']:
                    if addr[0] == lookup_addr:
                        LOG.debug(f'Using kubelet bind interface {name} as '
                                  f'bridge interface.')
                        return name

        # Alright, just try the first non-loopback interface
        for name, iface in h_ipdb.interfaces.items():
            if type(name) is int:  # Skip ones duplicated by id
                continue

            if iface['flags'] & pyroute2.netlink.rtnl.ifinfmsg.IFF_LOOPBACK:
                continue  # Skip loopback

            LOG.debug(f'Using interface {name} as bridge interface.')
            return name

        raise exceptions.CNIBindingFailure('Cannot find bridge interface for '
                                           'nested driver to use. Please set '
                                           '[binding]link_iface option.') 
開發者ID:openstack,項目名稱:kuryr-kubernetes,代碼行數:39,代碼來源:nested.py

示例4: test_tcp_v4

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import CONN_LISTEN [as 別名]
def test_tcp_v4(self):
        addr = ("127.0.0.1", get_free_port())
        with closing(bind_socket(AF_INET, SOCK_STREAM, addr=addr)) as sock:
            conn = self.check_socket(sock)
            assert not conn.raddr
            self.assertEqual(conn.status, psutil.CONN_LISTEN) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:8,代碼來源:test_connections.py

示例5: test_tcp_v6

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import CONN_LISTEN [as 別名]
def test_tcp_v6(self):
        addr = ("::1", get_free_port())
        with closing(bind_socket(AF_INET6, SOCK_STREAM, addr=addr)) as sock:
            conn = self.check_socket(sock)
            assert not conn.raddr
            self.assertEqual(conn.status, psutil.CONN_LISTEN) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:8,代碼來源:test_connections.py

示例6: _find_ngrok_inspection_port

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import CONN_LISTEN [as 別名]
def _find_ngrok_inspection_port(self):
        """
        :return (str, int):
        """
        for c in psutil.Process(self.ngrok_proc.pid).connections():
            if c.laddr[0] == '127.0.0.1' and c.raddr == () and c.status == psutil.CONN_LISTEN:
                return c.laddr
        raise RuntimeError('Did not find API interface of ngrok.') 
開發者ID:xybu,項目名稱:onedrived-dev,代碼行數:10,代碼來源:ngrok_server.py

示例7: popen

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import CONN_LISTEN [as 別名]
def popen(path, wait_for_listen=False):
    process = psutil.Popen(
        ['python', path],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )

    if wait_for_listen:
        # It would be more correct to check ``conn.status ==
        # psutil.CONN_LISTEN`` but this works
        try:
            while process.is_running() and not process.connections():
                pass
        except psutil.Error:
            raise AssertionError(process.stderr.read())

    success = True
    # noinspection PyBroadException
    try:
        yield process
    except:
        success = False
        raise
    finally:
        process.kill()
        if not success:
            dump_std_streams(path, process) 
開發者ID:uber,項目名稱:tchannel-python,代碼行數:29,代碼來源:test_examples.py

示例8: get_process_pid_by_listen_port

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import CONN_LISTEN [as 別名]
def get_process_pid_by_listen_port(self,
                                       listen_port: int = 80,
                                       listen_address: Union[None, str] = None,
                                       listen_proto: Union[None, str] = None,
                                       exit_on_failure: bool = True,
                                       exit_code: int = 27,
                                       quiet: bool = False) -> Union[None, List[int]]:
        """
        Get list of processes ID by listen TCP or UDP port
        :param listen_port: Listening TCP or UDP port integer (default: 80)
        :param listen_address: Listening IPv4 or IPv6 address string (default: None)
        :param listen_proto: Listening protocol string 'tcp' or 'udp' (default: 'tcp')
        :param exit_on_failure: Exit in case of error (default: False)
        :param exit_code: Set exit code integer (default: 27)
        :param quiet: Quiet mode, if True no console output (default: False)
        :return: List of processes ID by listen TCP or UDP port
        """
        pids: List[int] = list()
        try:
            assert 1 < listen_port < 65535, \
                'Bad listen port: ' + self.error_text(str(listen_port)) + \
                ' listen port must be in range: ' + self.info_text('1 - 65535')
            assert (listen_proto is None or listen_proto == 'tcp' or listen_proto == 'udp'), \
                'Bad value in listen proto: ' + self.error_text(str(listen_proto)) + \
                ' listen proto must be ' + self.info_text('None' + ' or ' + '\'tcp\'' + ' or ' + '\'udp\'')
            if listen_proto is None:
                listen_proto = 'tcp'
            for process in ps.process_iter():
                connections = process.connections()
                for connection in connections:
                    (address, port) = connection.laddr

                    if connection.type == sock.SOCK_STREAM and connection.status == ps.CONN_LISTEN:
                        proto = 'tcp'
                    elif connection.type == sock.SOCK_DGRAM:
                        proto = 'udp'
                    else:
                        continue

                    if listen_address is not None:
                        if address == listen_address and proto == listen_proto \
                                and port == listen_port and process.pid is not None:
                            pids.append(process.pid)
                    else:
                        if proto == listen_proto and port == listen_port and process.pid is not None:
                            pids.append(process.pid)
            return pids

        except ps.NoSuchProcess:
            return pids

        except AssertionError as Error:
            if not quiet:
                self.print_error(Error.args[0])
            if exit_on_failure:
                exit(exit_code)
            return None 
開發者ID:raw-packet,項目名稱:raw-packet,代碼行數:59,代碼來源:base.py


注:本文中的psutil.CONN_LISTEN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。