Find a free port in the given range
(start_port: int = 3000, end_port: int = 3100)
| 18 | |
| 19 | |
| 20 | def find_free_port(start_port: int = 3000, end_port: int = 3100) -> int: |
| 21 | """Find a free port in the given range""" |
| 22 | for port in range(start_port, end_port + 1): |
| 23 | try: |
| 24 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
| 25 | s.bind(('', port)) |
| 26 | return port |
| 27 | except OSError: |
| 28 | continue |
| 29 | |
| 30 | # If no port found in range, let the system choose |
| 31 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
| 32 | s.bind(('', 0)) |
| 33 | return s.getsockname()[1] |
| 34 | |
| 35 | |
| 36 | def get_static_path() -> Path: |
no outgoing calls
no test coverage detected