Ben Chuanlong Du's Blog

It is never too late to learn.

Hands on the Resource Module in Python

Tips and Traps

This module provides basic mechanisms for measuring and controlling system resources utilized by a process and its subprocesses. It cannot be used to check resource usage of other processes.

In [1]:
import resource

usage = resource.getrusage(resource.RUSAGE_SELF)
usage
Out[1]:
resource.struct_rusage(ru_utime=1.233378, ru_stime=0.28574299999999997, ru_maxrss=87670784, ru_ixrss=0, ru_idrss=0, ru_isrss=0, ru_minflt=39163, ru_majflt=0, ru_nswap=0, ru_inblock=0, ru_oublock=0, ru_msgsnd=85, ru_msgrcv=73, ru_nsignals=0, ru_nvcsw=17, ru_nivcsw=6092)
In [2]:
"{:,}".format(usage.ru_maxrss)
Out[2]:
'87,670,784'
In [ ]:

In [ ]:

In [ ]:

Comments