import socket
import contextlib


def find_free_port() -> int:
    """
    :return: a free port; mind that this is not multi-process safe and can lead to race conditions.
    """
    skt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    with contextlib.closing(skt):
        skt.bind(('', 0))
        _, port = skt.getsockname()
        return int(port)