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
2016-12-20 15:42:04 -05:00

14 lines
320 B
Python

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