import socket


def check_devserver_port_used(port):
    """check if port is ok to use for django devserver"""
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # immediately reuse a local socket in TIME_WAIT state
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    try:
        sock.bind(('127.0.0.1', port))
        used = False
    except socket.error:
        used = True
    finally:
        sock.close()
    return used