FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-137512: Add new constants in the resource module by serhiy-storchaka · Pull Request #137513 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (3) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
63 changes: 59 additions & 4 deletions Doc/library/resource.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ this module for those platforms.
Previously, it could be negative, such as -1 or -3.


.. 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.
Can be equal to :data:`RLIM_INFINITY`.

.. versionadded:: next


.. function:: getrlimit(resource)

Returns a tuple ``(soft, hard)`` with the current soft and hard limits of
Expand Down Expand Up @@ -181,8 +191,9 @@ platform.
.. data:: RLIMIT_VMEM

The largest area of mapped memory which the process may occupy.
Usually an alias of :const:`RLIMIT_AS`.

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


.. data:: RLIMIT_AS
Expand Down Expand Up @@ -235,16 +246,18 @@ platform.

.. versionadded:: 3.4


.. data:: RLIMIT_SBSIZE

The maximum size (in bytes) of socket buffer usage for this user.
This limits the amount of network memory, and hence the amount of mbufs,
that this user may hold at any time.

.. availability:: FreeBSD.
.. availability:: FreeBSD, NetBSD.

.. versionadded:: 3.4


.. data:: RLIMIT_SWAP

The maximum size (in bytes) of the swap space that may be reserved or
Expand All @@ -254,18 +267,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 @@ -274,6 +289,46 @@ 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_PIPEBUF

The maximum total size of in-kernel buffers for bi-directional pipes/fifos
that this user id is allowed to consume.

.. availability:: FreeBSD >= 14.2.

.. 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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', 'PIPEBUF']:
with contextlib.suppress(AttributeError):
self.assertIsInstance(getattr(resource, 'RLIMIT_' + attr), int)

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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_PIPEBUF`, :data:`~resource.RLIMIT_THREADS`,
:data:`~resource.RLIM_SAVED_CUR`, and :data:`~resource.RLIM_SAVED_MAX`.
29 changes: 29 additions & 0 deletions Modules/resource.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,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

Back | FazBrowse Home | New Git URL