import socket


def port_in_use(port, ip='localhost'):
    """Returns True when a port is in use at the given ip"""
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        return s.connect_ex((ip, port)) == 0