code: def write_pidfile(pidfile):
      
      pid = os.getpid()
      if pidfile:
          with open(pidfile, "w", encoding="utf-8") as fobj:
              fobj.write(six.u(str(pid)))
      return pid
docs: write current pid to pidfile.