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"
)
| 47 | |
| 48 | |
| 49 | def 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 | |
| 71 | def get_async_test_timeout() -> float: |
no outgoing calls
no test coverage detected