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


Python errno.EADDRINUSE屬性代碼示例

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


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

示例1: test_retry_limited

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def test_retry_limited(self):
    inet4_servers = [self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
                     for _ in range(wsgi_server._PORT_0_RETRIES)]
    inet6_servers = [self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
                     for _ in range(wsgi_server._PORT_0_RETRIES)]
    self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
    self.mox.StubOutWithMock(socket, 'getaddrinfo')
    socket.getaddrinfo('localhost', 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0,
                       socket.AI_PASSIVE).AndReturn(
                           [(None, None, None, None, ('127.0.0.1', 0, 'baz')),
                            (None, None, None, None, ('::1', 0, 'baz'))])
    for offset, (inet4_server, inet6_server) in enumerate(zip(
        inet4_servers, inet6_servers)):
      wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 0), None).AndReturn(
          inet4_server)
      inet4_server.start()
      inet4_server.port = offset + 1
      wsgi_server._SingleAddressWsgiServer(('::1', offset + 1), None).AndReturn(
          inet6_server)
      inet6_server.start().AndRaise(
          wsgi_server.BindError('message', (errno.EADDRINUSE, 'in use')))
      inet4_server.quit()
    self.mox.ReplayAll()
    self.assertRaises(wsgi_server.BindError, self.server.start)
    self.mox.VerifyAll() 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:27,代碼來源:wsgi_server_test.py

示例2: test_getsockaddrarg

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def test_getsockaddrarg(self):
        sock = socket.socket()
        self.addCleanup(sock.close)
        port = test_support.find_unused_port()
        big_port = port + 65536
        neg_port = port - 65536
        self.assertRaises(OverflowError, sock.bind, (HOST, big_port))
        self.assertRaises(OverflowError, sock.bind, (HOST, neg_port))
        # Since find_unused_port() is inherently subject to race conditions, we
        # call it a couple times if necessary.
        for i in itertools.count():
            port = test_support.find_unused_port()
            try:
                sock.bind((HOST, port))
            except OSError as e:
                if e.errno != errno.EADDRINUSE or i == 5:
                    raise
            else:
                break 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_socket.py

示例3: get_guest_cid

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def get_guest_cid(guest_cid):
    """
    Get an unused guest cid from system

    :param guest_cid: Requested guest cid
    :return Available guest cid
    """
    vsock_fd = os.open(VSOCK_PATH, os.O_RDWR)
    try:
        while guest_cid:
            cid_c = struct.pack('L', guest_cid)
            try:
                fcntl.ioctl(
                    vsock_fd, arch.VHOST_VSOCK_SET_GUEST_CID, cid_c)
            except IOError as e:
                if e.errno == errno.EADDRINUSE:
                    guest_cid += 1
                    continue
                else:
                    raise e
            else:
                return guest_cid
    finally:
        os.close(vsock_fd) 
開發者ID:avocado-framework,項目名稱:avocado-vt,代碼行數:26,代碼來源:utils_vsock.py

示例4: _bind_with_timeout

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def _bind_with_timeout(bind_function, args, n_tries=3, retry_interval_s=0.5):
    """Attempt to bind a socket a number of times with a short interval in between
    
    Especially on Linux, crashing out of a networkzero process can leave the sockets
    lingering and unable to re-bind on startup. We give it a few goes here to see if
    we can bind within a couple of seconds.
    """
    n_tries_left = n_tries
    while n_tries_left > 0:
        try:
            return bind_function(*args)
        except zmq.error.ZMQError as exc:
            _logger.warn("%s; %d tries remaining", exc, n_tries_left)
            n_tries_left -= 1
        except OSError as exc:
            if exc.errno == errno.EADDRINUSE:
                _logger.warn("%s; %d tries remaining", exc, n_tries_left)
                n_tries_left -= 1
            else:
                raise
    else:
        raise core.SocketAlreadyExistsError("Failed to bind after %s tries" % n_tries) 
開發者ID:tjguk,項目名稱:networkzero,代碼行數:24,代碼來源:discovery.py

示例5: _bind_by_name

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def _bind_by_name(self, socket, name):
        if not service_name_format.match(name):
            raise err.Error(errno.EFAULT)

        with self.lock:
            if self.snl.get(name) is not None:
                raise err.Error(errno.EADDRINUSE)
            addr = wks_map.get(name)
            if addr is None:
                try:
                    addr = 16 + self.sap[16:32].index(None)
                except ValueError:
                    raise err.Error(errno.EADDRNOTAVAIL)
            socket.bind(addr)
            self.sap[addr] = ServiceAccessPoint(addr, self)
            self.sap[addr].insert_socket(socket)
            self.snl[name] = addr 
開發者ID:nfcpy,項目名稱:nfcpy,代碼行數:19,代碼來源:llc.py

示例6: test_bind_by_addr

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def test_bind_by_addr(self, llc, raw, ldl, dlc):
            llc.bind(raw, 16)
            assert llc.getsockname(raw) == 16
            for i, sock in enumerate([ldl, dlc]):
                with pytest.raises(nfc.llcp.Error) as excinfo:
                    llc.bind(sock, 16)
                assert excinfo.value.errno == errno.EACCES
            llc.bind(ldl, 63)
            assert llc.getsockname(ldl) == 63
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.bind(dlc, 63)
            assert excinfo.value.errno == errno.EADDRINUSE
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.bind(dlc, 64)
            assert excinfo.value.errno == errno.EFAULT
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.bind(dlc, -1)
            assert excinfo.value.errno == errno.EFAULT
            llc.bind(dlc, 62)
            assert llc.getsockname(dlc) == 62 
開發者ID:nfcpy,項目名稱:nfcpy,代碼行數:22,代碼來源:test_llcp_llc.py

示例7: test_bind_by_name

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def test_bind_by_name(self, llc, raw, ldl, dlc):
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.bind(dlc, 'urn:nfc:snep')
            assert excinfo.value.errno == errno.EFAULT
            llc.bind(dlc, 'urn:nfc:sn:snep')
            assert llc.getsockname(dlc) == 4
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.bind(ldl, 'urn:nfc:sn:snep')
            assert excinfo.value.errno == errno.EADDRINUSE
            llc.bind(ldl, 'urn:nfc:xsn:nfcpy.org:service')
            assert llc.getsockname(ldl) == 16
            for sap in range(17, 32):
                sock = llc.socket(nfc.llcp.llc.RAW_ACCESS_POINT)
                llc.bind(sock, 'urn:nfc:sn:use_sap-{}'.format(sap))
                assert llc.getsockname(sock) == sap
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.bind(raw, 'urn:nfc:sn:sap-32')
            assert excinfo.value.errno == errno.EADDRNOTAVAIL 
開發者ID:nfcpy,項目名稱:nfcpy,代碼行數:20,代碼來源:test_llcp_llc.py

示例8: find_available_port

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def find_available_port(port_range=(49152, 65535), max_tries=1000):
    low, high = port_range

    port = low
    try_no = 0

    while try_no < max_tries:
        try_no += 1
        port = random.randint(low, high)
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            sock.bind(('localhost', port))
        except socket.error as e:
            if e.errno == errno.EADDRINUSE:
                continue
        finally:
            sock.close()

        break
    else:
        port = None

    return port 
開發者ID:edgedb,項目名稱:edgedb,代碼行數:25,代碼來源:cluster.py

示例9: find_available_port

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def find_available_port(port_range=(49152, 65535), max_tries=1000):
        low, high = port_range

        port = low
        try_no = 0

        while try_no < max_tries:
            try_no += 1
            port = random.randint(low, high)
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            try:
                sock.bind(('localhost', port))
            except socket.error as e:
                if e.errno == errno.EADDRINUSE:
                    continue
                raise
            finally:
                sock.close()

            break
        else:
            port = None

        return port 
開發者ID:edgedb,項目名稱:edgedb,代碼行數:26,代碼來源:main.py

示例10: test_getsockaddrarg

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def test_getsockaddrarg(self):
        sock = socket.socket()
        self.addCleanup(sock.close)
        port = support.find_unused_port()
        big_port = port + 65536
        neg_port = port - 65536
        self.assertRaises(OverflowError, sock.bind, (HOST, big_port))
        self.assertRaises(OverflowError, sock.bind, (HOST, neg_port))
        # Since find_unused_port() is inherently subject to race conditions, we
        # call it a couple times if necessary.
        for i in itertools.count():
            port = support.find_unused_port()
            try:
                sock.bind((HOST, port))
            except OSError as e:
                if e.errno != errno.EADDRINUSE or i == 5:
                    raise
            else:
                break 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:21,代碼來源:test_socket.py

示例11: test_create_server_addr_in_use

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def test_create_server_addr_in_use(self):
        sock_ob = socket.socket(type=socket.SOCK_STREAM)
        sock_ob.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock_ob.bind(('0.0.0.0', 0))

        f = self.loop.create_server(MyProto, sock=sock_ob)
        server = self.loop.run_until_complete(f)
        sock = server.sockets[0]
        host, port = sock.getsockname()

        f = self.loop.create_server(MyProto, host=host, port=port)
        with self.assertRaises(OSError) as cm:
            self.loop.run_until_complete(f)
        self.assertEqual(cm.exception.errno, errno.EADDRINUSE)

        server.close() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:test_events.py

示例12: __call__

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def __call__(self, group_id: Optional[str] = None) -> bool:
        import socket
        name = '{}-ipc-{}'.format(appname, os.geteuid())
        if group_id:
            name += '-{}'.format(group_id)

        s = socket.socket(family=socket.AF_UNIX)
        # First try with abstract UDS
        addr = '\0' + name
        try:
            s.bind(addr)
        except OSError as err:
            if err.errno == errno.ENOENT:
                return single_instance_unix(name)
            if err.errno == errno.EADDRINUSE:
                s.connect(addr)
                self.socket = s
                return False
            raise
        s.listen()
        self.socket = s  # prevent garbage collection from closing the socket
        s.set_inheritable(False)
        atexit.register(remove_socket_file, s)
        return True 
開發者ID:kovidgoyal,項目名稱:kitty,代碼行數:26,代碼來源:utils.py

示例13: is_port_busy

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def is_port_busy(host, port, reconnect):
    socket_to_check = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try:
        socket_to_check.bind((host, port))
    except socket.error as exception:
        if exception.errno == errno.EADDRINUSE:
            if not reconnect:
                print("Port is already in use")
            return True

        print(f'something else raised in the socket: {exception}')
    finally:
        socket_to_check.close()

    return False 
開發者ID:IBM,項目名稱:clai,代碼行數:18,代碼來源:clai_run.py

示例14: _create_listening_socket

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def _create_listening_socket(allow_remote, requested_port, retries=20):
        # The intention of this function is to contain the socket creation code
        # along with all the searching and retrying code. If a specific port is requested
        # and it is not available a socket.error will be raised.
        for retry in reversed(range(retries)):
            sock = None
            try:
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                sock.settimeout(0.25)
                # find an unused port and avoid blocked ports
                # see: dxr.mozilla.org/mozilla-central/source/netwerk/base/nsIOService.cpp
                port = random.randint(0x2000, 0xFFFF) if requested_port is None else requested_port
                sock.bind(("0.0.0.0" if allow_remote else "127.0.0.1", port))
                sock.listen(5)
            except (OSError, socket.error) as soc_e:
                if sock is not None:
                    sock.close()
                if retry > 1 and soc_e.errno in (errno.EADDRINUSE, 10013):
                    time.sleep(0.1)
                    continue
                raise
            break
        return sock 
開發者ID:MozillaSecurity,項目名稱:grizzly,代碼行數:26,代碼來源:core.py

示例15: _try_open_unix_domain_socket

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EADDRINUSE [as 別名]
def _try_open_unix_domain_socket(socket_path):
    try:
        return eventlet.listen(socket_path, socket.AF_UNIX)
    except socket.error as e:
        if e.errno != errno.EADDRINUSE:
            # NOTE(harlowja): Some other non-address in use error
            # occurred, since we aren't handling those, re-raise
            # and give up...
            raise
        else:
            # Attempt to remove the file before opening it again.
            try:
                os.unlink(socket_path)
            except OSError as e:
                if e.errno != errno.ENOENT:
                    # NOTE(harlowja): File existed, but we couldn't
                    # delete it, give up...
                    raise
            return eventlet.listen(socket_path, socket.AF_UNIX) 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:21,代碼來源:eventlet_backdoor.py


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