当前位置: 首页>>代码示例>>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;未经允许,请勿转载。