Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions Doc/library/resource.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ this module for those platforms.
Constant used to represent the limit for an unlimited resource.


.. data:: RLIM_SAVED_CUR
.. data:: RLIM_SAVED_MAX

Constants used to represent the soft and hard limit values if they
cannot be represented in the ``rlim_t`` value in C.
On FreeBSD they are aliases of :data:`RLIM_INFINITY`.

.. availability:: Solaris, AIX, FreeBSD

.. versionadded:: next


.. function:: getrlimit(resource)

Returns a tuple ``(soft, hard)`` with the current soft and hard limits of
Expand Down Expand Up @@ -177,7 +189,7 @@ platform.

The largest area of mapped memory which the process may occupy.

.. availability:: FreeBSD >= 11.
.. availability:: Solaris, FreeBSD.


.. data:: RLIMIT_AS
Expand Down Expand Up @@ -230,6 +242,7 @@ platform.

.. versionadded:: 3.4


.. data:: RLIMIT_SBSIZE

The maximum size (in bytes) of socket buffer usage for this user.
Expand All @@ -240,6 +253,7 @@ platform.

.. versionadded:: 3.4


.. data:: RLIMIT_SWAP

The maximum size (in bytes) of the swap space that may be reserved or
Expand All @@ -249,18 +263,20 @@ platform.
`tuning(7) <https://man.freebsd.org/cgi/man.cgi?query=tuning&sektion=7>`__
for a complete description of this sysctl.

.. availability:: FreeBSD.
.. availability:: FreeBSD >= 8.

.. versionadded:: 3.4


.. data:: RLIMIT_NPTS

The maximum number of pseudo-terminals created by this user id.

.. availability:: FreeBSD.
.. availability:: FreeBSD >= 8.

.. versionadded:: 3.4


.. data:: RLIMIT_KQUEUES

The maximum number of kqueues this user id is allowed to create.
Expand All @@ -269,6 +285,36 @@ platform.

.. versionadded:: 3.10


.. data:: RLIMIT_NTHR

The maximum number of threads for this user id, not counting the main
and kernel threads.

.. availability:: NetBSD >= 7.0.

.. versionadded:: next


.. data:: RLIMIT_THREADS

The maximum number of threads each process can create.

.. availability:: AIX.

.. versionadded:: next


.. data:: RLIMIT_UMTXP

The limit of the number of process-shared Posix thread library objects
allocated by user id.

.. availability:: FreeBSD >= 11.

.. versionadded:: next


Resource Usage
--------------

Expand Down
9 changes: 9 additions & 0 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ os.path
the resulting path can be missing but it will be free of symlinks.
(Contributed by Petr Viktorin for :cve:`2025-4517`.)

resource
--------

* Add new constants: :data:`~resource.RLIMIT_NTHR`,
:data:`~resource.RLIMIT_UMTXP`, :data:`~resource.RLIMIT_THREADS`,
:data:`~resource.RLIM_SAVED_CUR`, and :data:`~resource.RLIM_SAVED_MAX`.
(Contributed by Serhiy Storchaka in :gh:`137512`.)


shelve
------

Expand Down
11 changes: 10 additions & 1 deletion Lib/test/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,23 @@ def test_pagesize(self):
self.assertIsInstance(pagesize, int)
self.assertGreaterEqual(pagesize, 0)

def test_contants(self):
self.assertIsInstance(resource.RLIM_INFINITY, int)
if sys.platform.startswith(('freebsd', 'solaris', 'sunos', 'aix')):
self.assertHasAttr(resource, 'RLIM_SAVED_CUR')
self.assertHasAttr(resource, 'RLIM_SAVED_MAX')
if hasattr(resource, 'RLIM_SAVED_CUR'):
self.assertIsInstance(resource.RLIM_SAVED_CUR, int)
self.assertIsInstance(resource.RLIM_SAVED_MAX, int)

@unittest.skipUnless(sys.platform in ('linux', 'android'), 'Linux only')
def test_linux_constants(self):
for attr in ['MSGQUEUE', 'NICE', 'RTPRIO', 'RTTIME', 'SIGPENDING']:
with contextlib.suppress(AttributeError):
self.assertIsInstance(getattr(resource, 'RLIMIT_' + attr), int)

def test_freebsd_contants(self):
for attr in ['SWAP', 'SBSIZE', 'NPTS']:
for attr in ['SWAP', 'SBSIZE', 'NPTS', 'UMTXP', 'VMEM']:
with contextlib.suppress(AttributeError):
self.assertIsInstance(getattr(resource, 'RLIMIT_' + attr), int)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Add new constants in the :mod:`resource` module:
:data:`~resource.RLIMIT_NTHR`, :data:`~resource.RLIMIT_UMTXP`,
:data:`~resource.RLIMIT_THREADS`, :data:`~resource.RLIM_SAVED_CUR`, and
:data:`~resource.RLIM_SAVED_MAX`.
29 changes: 29 additions & 0 deletions Modules/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,38 @@ resource_exec(PyObject *module)
ADD_INT(module, RLIMIT_KQUEUES);
#endif

#ifdef RLIMIT_NTHR
ADD_INT(module, RLIMIT_NTHR);
#endif

#ifdef RLIMIT_THREADS
ADD_INT(module, RLIMIT_THREADS);
#endif

#ifdef RLIMIT_UMTXP
ADD_INT(module, RLIMIT_UMTXP);
#endif

#ifdef RLIMIT_PIPEBUF
ADD_INT(module, RLIMIT_PIPEBUF);
#endif

if (PyModule_Add(module, "RLIM_INFINITY", rlim2py(RLIM_INFINITY)) < 0) {
return -1;
}

#ifdef RLIM_SAVED_CUR
if (PyModule_Add(module, "RLIM_SAVED_CUR", rlim2py(RLIM_SAVED_CUR)) < 0) {
return -1;
}
#endif

#ifdef RLIM_SAVED_MAX
if (PyModule_Add(module, "RLIM_SAVED_MAX", rlim2py(RLIM_SAVED_MAX)) < 0) {
return -1;
}
#endif

return 0;

#undef ADD_INT
Expand Down
Loading