Spaces:
Sleeping
Sleeping
File size: 370 Bytes
2ba4412 |
1 2 3 4 5 6 7 8 9 |
import socket
from contextlib import closing
def find_free_port():
""" https://stackoverflow.com/questions/1365265/on-localhost-how-do-i-pick-a-free-port-number """
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 str(s.getsockname()[1]) |