'Creates a lock file for the given document. If timeout is set,
it will retry every 1 second for acquiring the lock again
:param timeout: Timeout in seconds, default 0'

def lock(self, timeout=None):

    signature = self.get_signature()
    if file_lock.lock_exists(signature):
        lock_exists = True
        if timeout:
            for i in range(timeout):
                time.sleep(1)
                if (not file_lock.lock_exists(signature)):
                    lock_exists = False
                    break
        if lock_exists:
            raise frappe.DocumentLockedError
    file_lock.create_lock(signature)
