code: def run_transaction(transactor, callback):
      
      if isinstance(transactor, sqlalchemy.engine.Connection):
          return _txn_retry_loop(transactor, callback)
      elif isinstance(transactor, sqlalchemy.engine.Engine):
          with transactor.connect() as connection:
              return _txn_retry_loop(connection, callback)
      elif isinstance(transactor, sqlalchemy.orm.sessionmaker):
          session = transactor(autocommit=True)
          return _txn_retry_loop(session, callback)
      else:
          raise TypeError("don't know how to run a transaction on %s", type(transactor))
docs: Run a transaction with retries.
  
      ``callback()`` will be called with one argument to execute the
      transaction. ``callback`` may be called more than once; it should have
      no side effects other than writes to the database on the given
      connection. ``callback`` should not call ``commit()` or ``rollback()``;
      these will be called automatically.
  
      The ``transactor`` argument may be one of the following types:
      * `sqlalchemy.engine.Connection`: the same connection is passed to the callback.
      * `sqlalchemy.engine.Engine`: a connection is created and passed to the callback.
      * `sqlalchemy.orm.sessionmaker`: a session is created and passed to the callback.