流行的python mysql模块“MySQLdb”似乎有内存泄漏问题。 下面的代码:Python MySQLdb模块内存泄露
conn = MySQLdb.connect(...)
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
sql = "select * from `test`"
cursor.execute(sql) #leak start
cursor.close()
conn.close()
time.sleep(20)
假设test
是十亿记录的表。我跑了Python代码,并在同一时间执行
ps aux | awk '{print $2, $4, $11}' | grep python
,其结果是,内存使用提高到47.0%,从来没有回去,即使我关闭游标和康涅狄格州。有任何想法吗?
http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm – unutbu
我有同样的问题。多年来一直没有找到解决办法。相反,我只写了一个cronjob,当内存变高时重新启动服务器。这是一个黑客,但它的工作原理。 –