import socket


def is_port_in_use(port, hostname='localhost'):
    """Check if given port is already used locally"""
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
        return sock.connect_ex((hostname, port)) == 0