From: youguanxinqing Date: Mon, 11 Jan 2021 14:35:20 +0000 (+0800) Subject: Add 'address' keyword control binded address #2969 X-Git-Tag: v6.2.0b1~52^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e7b95cd3d8d31f08a1a827b600e63ce2ab8ad42;p=thirdparty%2Ftornado.git Add 'address' keyword control binded address #2969 --- diff --git a/tornado/testing.py b/tornado/testing.py index 98b54eabb..e8d6d29ed 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -45,17 +45,17 @@ if typing.TYPE_CHECKING: _NON_OWNED_IOLOOPS = AsyncIOMainLoop -def bind_unused_port(reuse_port: bool = False) -> Tuple[socket.socket, int]: +def bind_unused_port(reuse_port: bool = False, address: str = "127.0.0.1") -> Tuple[socket.socket, int]: """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 + Default binds to ``127.0.0.1`` without resolving the name ``localhost``. """ sock = netutil.bind_sockets( - 0, "127.0.0.1", family=socket.AF_INET, reuse_port=reuse_port + 0, address, family=socket.AF_INET, reuse_port=reuse_port )[0] port = sock.getsockname()[1] return sock, port