Total memory used by Python process?

前端 未结 12 887
眼角桃花
眼角桃花 2020-11-22 04:28

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 tot

12条回答
  •  我寻月下人不归
    2020-11-22 04:55

    For Python 3.6 and psutil 5.4.5 it is easier to use memory_percent() function listed here.

    import os
    import psutil
    process = psutil.Process(os.getpid())
    print(process.memory_percent())
    

提交回复
热议问题