MCPcopy
hub / github.com/tornadoweb/tornado / bind_unused_port

Function bind_unused_port

tornado/testing.py:49–68  ·  view source on GitHub ↗

Binds a server socket to an available port on localhost. Returns a tuple (socket, port). .. versionchanged:: 4.4 Always binds to ``127.0.0.1`` without resolving the name ``localhost``. .. versionchanged:: 6.2 Added optional ``address`` argument to override

(
    reuse_port: bool = False, address: str = "127.0.0.1"
)

Source from the content-addressed store, hash-verified

47
48
49def bind_unused_port(
50 reuse_port: bool = False, address: str = "127.0.0.1"
51) -> Tuple[socket.socket, int]:
52 """Binds a server socket to an available port on localhost.
53
54 Returns a tuple (socket, port).
55
56 .. versionchanged:: 4.4
57 Always binds to ``127.0.0.1`` without resolving the name
58 ``localhost``.
59
60 .. versionchanged:: 6.2
61 Added optional ``address`` argument to
62 override the default "127.0.0.1".
63 """
64 sock = netutil.bind_sockets(
65 0, address, family=socket.AF_INET, reuse_port=reuse_port
66 )[0]
67 port = sock.getsockname()[1]
68 return sock, port
69
70
71def get_async_test_timeout() -> float:

Callers 15

setUpMethod · 0.90
test_multi_processMethod · 0.90
setUpMethod · 0.90
test_chunked_closeMethod · 0.90
init_serverMethod · 0.90
test_reuse_portMethod · 0.90
setUpMethod · 0.90
make_iostream_pairMethod · 0.90
setUpMethod · 0.90
connect_to_serverMethod · 0.90
setUpMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected