Python resource: measure and limit Unix resource use
Answer: The resource module measures and controls system resources used by a program on Unix.
Where it runs
The module is available on Unix, and not on WASI.
Symbolic constants name particular system resources.
You can ask about the current process or its children.
A failed system call raises OSError.
Soft and hard limits
Each resource has a soft limit and a hard limit.
The soft limit is the current limit, and a process may change it over time.
The soft limit can never exceed the hard limit.
Only a super-user process can raise a hard limit.
getrlimit returns a tuple with the current soft and hard limits.
See also
Claims
- id: C1 claim: The module measures and controls system resources a program uses. source: S1 evidence: "measuring and controlling system resources utilized by a program"
- id: C2 claim: Each resource has a soft limit and a hard limit. source: S1 evidence: "a pair of limits: a soft limit and a hard limit"
- id: C3 claim: The soft limit can never exceed the hard limit. source: S2 evidence: "The soft limit can never exceed the hard limit"
- id: C4 claim: getrlimit returns the current soft and hard limits. source: S1 evidence: "Returns a tuple (soft, hard) with the current soft and hard limits"
Sources
- [S1] resource — Resource usage information. Python Software Foundation. https://docs.python.org/3/library/resource.html . License: PSF License Version 2. Accessed 2026-11-24.
- [S2] resource documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/resource.rst . License: PSF License Version 2. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, resource — Resource usage information; CPython, resource documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, resource — Resource usage information; CPython, resource documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python resource: measure and limit Unix resource use." iinventedlight Library, iil:note:vv08d587, version of 2026-11-24. https://iinventedlight.com/library/notes/python-resource/. License: CC-BY-4.0.
@misc{iil_note_vv08d587,
author = {{iinventedlight}},
title = {{Python resource: measure and limit Unix resource use}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/python-resource/},
note = {Permanent ID iil:note:vv08d587. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-resource.schema.json (schema; CC-BY-4.0)
- python-resource.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-resource.md.