original_docstring: crates a lock to prevent premature folder cleanup
docstring: crates a lock to prevent premature folder cleanup
docstring_tokens: crates a lock to prevent premature folder cleanup
code: def create_cleanup_lock(p):
      """crates a lock to prevent premature folder cleanup"""
      lock_path = get_lock_path(p)
      try:
          fd = os.open(str(lock_path), os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o644)
      except OSError as e:
          if e.errno == errno.EEXIST:
              six.raise_from(
                  EnvironmentError("cannot create lockfile in {path}".format(path=p)), e
              )
          else:
              raise
      else:
          pid = os.getpid()
          spid = str(pid)
          if not isinstance(spid, bytes):
              spid = spid.encode("ascii")
          os.write(fd, spid)
          os.close(fd)
          if not lock_path.is_file():
              raise EnvironmentError("lock path got renamed after sucessfull creation")
          return lock_path
code_tokens: def create_cleanup_lock ( p ) : lock_path = get_lock_path ( p ) try : fd = os . open ( str ( lock_path ) , os . O_WRONLY | os . O_CREAT | os . O_EXCL , 0o644 ) except OSError as e : if e . errno == errno . EEXIST : six . raise_from ( EnvironmentError ( "cannot create lockfile in {path}" . format ( path = p ) ) , e ) else : raise else : pid = os . getpid ( ) spid = str ( pid ) if not isinstance ( spid , bytes ) : spid = spid . encode ( "ascii" ) os . write ( fd , spid ) os . close ( fd ) if not lock_path . is_file ( ) : raise EnvironmentError ( "lock path got renamed after sucessfull creation" ) return lock_path
short_docstring: crates a lock to prevent premature folder cleanup
short_docstring_tokens: crates a lock to prevent premature folder cleanup
comment: """crates a lock to prevent premature folder cleanup"""