import fcntl


def unlock_file(fp, close=False):
  """
    Unlock a file pointer.

    If close=True the file pointer will be closed after unlocking.

    Always returns True.
  """
  try:
    fcntl.flock(fp, fcntl.LOCK_UN)
  finally:
    if close:
      fp.close()
  return True