Python笔记-Can’t reconnect until invalid transaction is rolled back
Posted IT1995
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python笔记-Can’t reconnect until invalid transaction is rolled back相关的知识,希望对你有一定的参考价值。
原因是没有调用
session.rollback()
解决方法:
@contextmanager
def session_scope(self):
self.db_engine = create_engine(self.db_config, pool_pre_ping=True) # echo=True if needed to see background SQL
Session = sessionmaker(bind=self.db_engine)
session = Session()
try:
# this is where the "work" happens!
yield session
# always commit changes!
session.commit()
except:
# if any kind of exception occurs, rollback transaction
session.rollback()
raise
finally:
session.close()
另一种形式:
try:
......
......
......
......
except Exception:
import traceback
traceback.print_exc()
db.session.rollback()
pass
finally:
db.session.close()
pass
以上是关于Python笔记-Can’t reconnect until invalid transaction is rolled back的主要内容,如果未能解决你的问题,请参考以下文章
TensorFlow学习笔记(UTF-8 问题解决 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in po
Linux笔记-Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“)
Linux笔记-Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“)
Linux笔记-Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“)
python输出字符串,UnicodeEncodeError: 'ascii' codec can't encode characters in position问题(示例代码
Google Play 游戏服务 - 实时多人游戏 - STATUS_CLIENT_RECONNECT_REQUIRED