流行的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,當內存變高時重新啓動服務器。這是一個黑客,但它的工作原理。 –