def start_mem_check_thread(threshold=1024 * 1024 * 1024,
gc=False,
size_range=None,
interval=1
):
"""
Start a thread in background and in daemon mode, to watch memory usage.
If memory this process is using beyond `threshold`, a memory usage profile
is made and is written to root logger. And process is aborted.
`threshold`: maximum memory a process can use before abort.
`gc`: whether to run gc every time before checking memory usage.
`size_range`: in tuple, dump only object of size in this range.
`interval`: memory check interval.
"""
options = {
'threshold': threshold,
'gc': gc,
'size_range': size_range,
'interval': interval,
}
th = threading.Thread(target=mem_check, args=(options,))
th.daemon = True
th.start()
return th
评论列表
文章目录