Python Orm Peewee 错误

1
peewee.OperationalError: (2013, 'Lost connection to MySQL server during query ([Errno 104] Connection reset by peer)')

原因是 peewee 不会主动去重连数据库

https://github.com/coleifer/peewee/issues/1992

如果在事务中也不会主动链接可以用如下方式

https://github.com/coleifer/peewee/issues/2628

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
try:
MysqlClient.connect()
with MysqlClient.atomic():
for batch in chunked(lists, 100):
ProjectResourceUtilization.insert_many(
batch,
[
"cluster_name"
],
).execute()
MysqlClient.close()
return True, None
except Exception as error:
logging.info("项目资源使用率:" + str(error))
return False, str(error)