Python resource Module
Example
Get resource usage information for the current process:
import resource
usage = resource.getrusage(resource.RUSAGE_SELF)
print(f'CPU time: {usage.ru_utime:.2f} seconds')
Try it Yourself »
Definition and Usage
The resource module provides tools for measuring and controlling system resources used by a program.
Use it to query resource usage (CPU time, memory), set resource limits, or monitor system resource consumption on Unix systems.
Note: This module is only available on Unix/Linux systems. It is not available on Windows.
Members
| Member | Description |
|---|---|
| RLIMIT_AS | Maximum area (in bytes) of address space. |
| RLIMIT_CORE | Maximum size of core file. |
| RLIMIT_CPU | Maximum CPU time (in seconds). |
| RLIMIT_DATA | Maximum size of process's data segment. |
| RLIMIT_FSIZE | Maximum size of a file which the process may create. |
| RLIMIT_MEMLOCK | Maximum amount of memory that can be locked into RAM. |
| RLIMIT_NOFILE | Maximum number of open file descriptors. |
| RLIMIT_NPROC | Maximum number of processes the user can create. |
| RLIMIT_RSS | Maximum resident set size. |
| RLIMIT_STACK | Maximum size of the stack segment. |
| RLIM_INFINITY | Constant representing an unlimited resource. |
| RUSAGE_BOTH | Request resources for current process and children. |
| RUSAGE_CHILDREN | Request resources for child processes. |
| RUSAGE_SELF | Request resources for the calling process. |
| RUSAGE_THREAD | Request resources for the current thread. |
| error | Deprecated alias of OSError. |
| getpagesize() | Return the number of bytes in a system page. |
| getrlimit() | Return the current soft and hard limits of a resource. |
| getrusage() | Return resource usage information. |
| prlimit() | Get and set resource limits of an arbitrary process (Linux). |
| setrlimit() | Set new limits for a resource. |