Python:从Thread调用时解密失败或记录Mac的错误 [英] Python: decryption failed or bad record mac when calling from Thread

查看:118
本文介绍了Python:从Thread调用时解密失败或记录Mac的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码段中出现解密失败或错误的记录mac错误:

I'm getting a "decryption failed or bad record mac" error in this code-fragment:

conn = psycopg2.connect(...)
cursor = conn.cursor()
cursor.execute("SELECT id, ip FROM schema.table;")
rows = cursor.fetchall()
cursor.close()
conn.commit()
conn.close()

这在Thread的run()方法中被调用,在while(True)循环中多次被调用。
我只是使用psycopg2驱动程序打开了到PostgreSQL数据库的连接。

This is called in the run() method of a Thread, several times in a while(True) loop. I'm just opening a connection to my PostgreSQL database using the psycopg2 driver.

有什么想法可以安全地在Python线程中打开db连接?
我不知道是什么引起了这个错误。

Any idea of how safe is opening db connections into Threads in Python? I don't know what is raising this error.

推荐答案

好,看来我已经解决了问题。我创建了太多连接,似乎我的内存不足。
我收集了所有查询,并对一个庞大的查询执行一次cursor.execute(...),而不是执行数百个小型查询/连接。

Ok, looks like I've fixed the problem. I was creating too many connections and seems I was running out of memory or something. I gathered all the queries and do cursor.execute(...) once with a huge query, instead performing hundreds of small queries/connections.

conn = psycopg2.connect(...)
cursor = conn.cursor()
cursor.execute("SELECT id, ip FROM schema.table;")
rows = cursor.fetchall()
cursor.close()
conn.commit()
conn.close()
conn = None

这篇关于Python:从Thread调用时解密失败或记录Mac的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆