我收到以下错误:
Traceback (most recent call last):
main()
for item in session.query(Item).yield_per(10):
fetch = cursor.fetchmany(self._yield_per)
self.cursor, self.context)
l = self.process_rows(self._fetchmany_impl(size))
row = self._fetchone_impl()
self.__buffer_rows()
self.__rowbuffer = collections.deque(self.cursor.fetchmany(size))
sqlalchemy.exc.ProgrammingError: (ProgrammingError) named cursor isn't valid anymore None None
我怀疑调用 session.commit() 会干扰 .yield_per
sessionmaker_ = sessionmaker(autocommit=False, autoflush=False, bind=engine)
session = scoped_session(sessionmaker_)
def foo(item):
# DO something to the item
session.add(item)
session.commit()
def main():
for item in session.query(Item).yield_per(5):
foo(item)
任何想法?