Creates a listening unix socket.

    If a socket with the given name already exists, it will be deleted.
    If any other file with that name exists, an exception will be
    raised.

    Returns a socket object (not a list of socket objects like
    `bind_sockets`)

def bind_unix_socket(file_, mode=0o600, backlog=_DEFAULT_BACKLOG):
    """Creates a listening unix socket.

    If a socket with the given name already exists, it will be deleted.
    If any other file with that name exists, an exception will be
    raised.

    Returns a socket object (not a list of socket objects like
    `bind_sockets`)
    """
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.setblocking(0)
    try:
        st = os.stat(file_)
    except OSError as err:
        if err.errno != errno.ENOENT:
            raise
    else:
        if stat.S_ISSOCK(st.st_mode):
            os.remove(file_)
        else:
            raise ValueError('File %s exists and is not a socket', file_)
    sock.bind(file_)
    os.chmod(file_, mode)
    sock.listen(backlog)
    return sock