code: def txn(self, overwrite=False, lock=True):
          
          if lock:
              self._lock.acquire()
          try:
              new_state, existing_generation = self.state_and_generation
              new_state = copy.deepcopy(new_state)
              yield new_state
              if overwrite:
                  existing_generation = None
              self.set_state(new_state, existing_generation=existing_generation)
          finally:
              if lock:
                  self._lock.release()
docs: Context manager for a state modification transaction.