```@contextmanager def owner_printing_file_lock(pa...
# general
b
Copy code
@contextmanager
def owner_printing_file_lock(path):
  lock = InterProcessLock(path)

  lock.acquire(blocking=False)

  if not lock.acquired:
    with open(lock.path, 'rb') as f:
      lockfile_contents = f.read().decode('utf-8', 'replace')
      print('Waiting on pants process to complete: {}'.format(lockfile_contents), file=sys.stderr)
    lock.acquire()

  with open(lock.path, 'wb') as f:
    current_process = psutil.Process()
    message = '{} ({})'.format(current_process.pid, ' '.join(current_process.cmdline()))
    f.write(message.encode('utf-8'))
  yield lock
  with open(lock.path, 'w'):
    pass

  lock.release()