From 1e7b95cd3d8d31f08a1a827b600e63ce2ab8ad42 Mon Sep 17 00:00:00 2001 From: youguanxinqing Date: Mon, 11 Jan 2021 22:35:20 +0800 Subject: [PATCH] Add 'address' keyword control binded address #2969 --- tornado/testing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 -- 2.47.2