import fcntl


def lock_file(fileno: int):
    """Lock file.  Returns ``True`` if succeeded, ``False`` otherwise."""
    try:
        # Try to lock file exclusively and in non-blocking fashion
        fcntl.flock(fileno, fcntl.LOCK_EX | fcntl.LOCK_NB)
    except IOError:
        return False
    else:
        return True