This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/test/testutil.py

15 lines
320 B
Python
Raw Normal View History

import socket
def get_open_port():
""" Retrieves an open port on the system. """
# Bind a socket to a random port. We can then ask for the port number,
# and return it.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", 0))
s.listen(1)
port = s.getsockname()[1]
s.close()
return port