import socket


def is_port_available(port, host='127.0.0.1'):
    """check whether a port is in use return True if the port is available else
    False."""
    s = None
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(1)
        s.connect((host, int(port)))
        return True
    except socket.error:
        return False
    finally:
        if s:
            s.close()