def acquire(self, timeout=None):
timeout = timeout if timeout is not None else self.timeout<EOL>end_time = time.time()<EOL>if timeout is not None and timeout > <NUM_LIT:0>:<EOL><INDENT>end_time += timeout<EOL><DEDENT>while True:<EOL><INDENT>try:<EOL><INDENT>write_pid_to_pidfile(self.path)<EOL><DEDENT>except OSError as exc:<EOL><INDENT>if exc.errno == errno.EEXIST:<EOL><INDENT>if time.time() > end_time:<EOL><INDENT>if timeout is not None and timeout > <NUM_LIT:0>:<EOL><INDENT>raise LockTimeout("<STR_LIT>"<EOL>"<STR_LIT>" %<EOL>self.path)<EOL><DEDENT>else:<EOL><INDENT>raise AlreadyLocked("<STR_LIT>" %<EOL>self.path)<EOL><DEDENT><DEDENT>time.sleep(timeout is not None and timeout / <NUM_LIT:10> or <NUM_LIT:0.1>)<EOL><DEDENT>else:<EOL><INDENT>raise LockFailed("<STR_LIT>" % self.path)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return<EOL><DEDENT><DEDENT>
Acquire the lock.

        Creates the PID file for this lock, or raises an error if
        the lock could not be acquired.