防止內存泄漏Python工具:memory_utils

jopen 11年前發布 | 20K 次閱讀 Python開發 memory_utils

這是一個Python實用程序用來幫助對抗,防止內存泄漏。

check_memory

Will check the current rss memory against the memory_utils set memory limit. And if it crosses that limit it will raise a MemoryTooBigException

pip install memory_utils

import memory_utils memory_utils.set_memory_limit(200 * memory_utils.MEGABYTES)

.... else where

memory_utils.check_memory()</pre>

memory_watcher

Often you will want to do your check_memory at a _safe_ place. Also memory leaks often happen within a loop. We created memory_watcher with those concepts in mind

for account in memory_watcher(Account.objects):
    account.do_something_memory_intensive()
    account.save()

This will call check_memory before each iteration

項目主頁:http://www.baiduhome.net/lib/view/home/1414738923403

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!