防止内存泄漏Python工具:memory_utils
jopen
10年前
这是一个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()
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