2019年4月10日 星期三

[ Python 常見問題 ] Total memory used by Python process?

Source From Here 
Question 
Is there a way for a Python program to determine how much memory it's currently using? I've seen discussions about memory usage for a single object, but what I need is total memory usage for the process, so that I can determine when it's necessary to start discarding cached data. 

How-To 
Here is a useful solution that works for various operating systems, including Linux, Windows 7, etc.: 
>>> import os
>>> import psutil
>>> process = psutil.Process(os.getpid())
>>> print(process.memory_info().rss) # in byte
10186752

Note: do pip install psutil if it is not installed yet. 

Supplement 
Python 常見問題 - fatal error: Python.h: No such file or directory

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...