code: def write(path):
      
      pid = os.getpid()
      logging.info("Writing PID %s to '%s'", pid, path)
      try:
          pidfile = open(path, 'wb')
          # get a non-blocking exclusive lock
          fcntl.flock(pidfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
          # clear out the file
          pidfile.seek(0)
          pidfile.truncate(0)
          # write the pid
          pidfile.write(str(pid))
      finally:
          try:
              pidfile.close()
          except:
              pass
docs: Writes the current process id to the given pidfile.
  
      :type  path: str
      :param path: The name of the pidfile.