Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Hands on the Resource Module in Python

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

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.

import resource

usage = resource.getrusage(resource.RUSAGE_SELF)
usage
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)
"{:,}".format(usage.ru_maxrss)
'87,670,784'