def create_cleanup_lock(p):
lock_path = get_lock_path(p)<EOL>try:<EOL><INDENT>fd = os.open(str(lock_path), os.O_WRONLY | os.O_CREAT | os.O_EXCL, <NUM_LIT>)<EOL><DEDENT>except OSError as e:<EOL><INDENT>if e.errno == errno.EEXIST:<EOL><INDENT>six.raise_from(<EOL>EnvironmentError("<STR_LIT>".format(path=p)), e<EOL>)<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>else:<EOL><INDENT>pid = os.getpid()<EOL>spid = str(pid)<EOL>if not isinstance(spid, bytes):<EOL><INDENT>spid = spid.encode("<STR_LIT:ascii>")<EOL><DEDENT>os.write(fd, spid)<EOL>os.close(fd)<EOL>if not lock_path.is_file():<EOL><INDENT>raise EnvironmentError("<STR_LIT>")<EOL><DEDENT>return lock_path<EOL><DEDENT>
crates a lock to prevent premature folder cleanup