mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-17 06:52:56 +00:00
Better tests directory structure (#2231)
This commit is contained in:
12
tests/utils/find_free_port.py
Normal file
12
tests/utils/find_free_port.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
import socket
|
||||
from contextlib import closing
|
||||
|
||||
|
||||
def find_free_port() -> str:
|
||||
"""Returns the available host port. Can be called in multiple threads/processes."""
|
||||
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
|
||||
s.bind(("", 0))
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
return s.getsockname()[1] # type: ignore
|
Reference in New Issue
Block a user