code: def _lock(self, timeout_ms=-1):
          
          vbox = VirtualBox()
          machine = vbox.find_machine(self.machine_name)
          wait_time = 0
          while True:
              session = Session()
              try:
                  machine.lock_machine(session, LockType.write)
              except Exception as exc:
                  if timeout_ms != -1 and wait_time > timeout_ms:
                      raise ValueError("Failed to acquire lock - %s" % exc)
                  time.sleep(1)
                  wait_time += 1000
              else:
                  try:
                      yield session
                  finally:
                      session.unlock_machine()
                  break
docs: Exclusive lock over root machine