Tracking *maximum* memory usage by a Python function

前端 未结 8 1687
轻奢々
轻奢々 2020-12-02 09:07

I want to find out what the maximum amount of RAM allocated during the call to a function is (in Python). There are other questions on SO related to tracking RAM usage:

8条回答
  •  情话喂你
    2020-12-02 10:00

    This appears to work under Windows. Don't know about other operating systems.

    In [50]: import os
    
    In [51]: import psutil
    
    In [52]: process = psutil.Process(os.getpid())
    
    In [53]: process.get_ext_memory_info().peak_wset
    Out[53]: 41934848
    

提交回复
热议问题