python-psutil: RLIM_INFINITY changes in python 3.15

Maximiliano Curia <[email protected]>
Newsgroups gmane.linux.debian.devel.python
Message-ID <[email protected]>
Package: src:python-psutil
Version: 7.1.0-1
User: [email protected]
Usertags: python3.15

Hi!

While rebuilding packages against Python 3.15 we found that
python-psutil produces some errors in the tests. This is due to a change
in Python 3.15 resources handling
(https://docs.python.org/3.15/whatsnew/3.15.html#porting-to-python-3-15):

  - resource.RLIM_INFINITY is now always positive. Passing a negative
    integer value that corresponded to its old value (such as -1 or -3,
    depending on platform) to resource.setrlimit() and resource.prlimit()
    is now deprecated. (Contributed by Serhiy Storchaka in gh-137044.)
  
While python-psutil tests rely on RLIM_INFINITY to be -1.

Note that this was already a problem when building against pypy and the
tests were skipped to build against pypy.

As there are many dependencies that require psutil I'm applying the
attached patch to the package in the build sandbox (we are using the
debusine.debian.net provided by freexian to make the test the rebuilds).
But while the patch seems to be inline with what upstream plans to do
for the version 8.0 it might be worth having a conversation as otherwise
psutils.RLIM_INFINITY will be different to resource.RLIM_INFINITY. Which
seems to be an overlooked consequence of the current fix.

(To be fair, allowing psutils.RLIM_INFINITY to change when psutil builds
against Python 3.15 is a minor api breakage, which might not be
acceptable for python-psutil upstream developers.)

Please consider either applying this patch or something similar to the
psutil package to allow it to build against Python 3.15.

Happy hacking,
-- 
"It is practically impossible to teach good programming to students that have 
had a prior exposure to BASIC: as potential programmers they are mentally 
mutilated beyond hope of regeneration."
-- Edsger W. Dijkstra
Saludos /\/\ /\ >< `/
python-psutil_7.1.0-1.1.debdiff (text/plain, 7.8 KB)
diff -Nru python-psutil-7.1.0/debian/changelog python-psutil-7.1.0/debian/changelog
--- python-psutil-7.1.0/debian/changelog	2025-10-05 08:26:16.000000000 +0200
+++ python-psutil-7.1.0/debian/changelog	2026-08-15 12:05:08.000000000 +0200
@@ -1,3 +1,9 @@
+python-psutil (7.1.0-1.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+
+ -- Maximiliano Curia <[email protected]>  Sat, 15 Aug 2026 12:05:08 +0200
+
 python-psutil (7.1.0-1) unstable; urgency=medium
 
   * New upstream release
diff -Nru python-psutil-7.1.0/debian/patches/0001-dont-depend-on-install-when-running-tests.patch python-psutil-7.1.0/debian/patches/0001-dont-depend-on-install-when-running-tests.patch
--- python-psutil-7.1.0/debian/patches/0001-dont-depend-on-install-when-running-tests.patch	2025-10-05 08:26:16.000000000 +0200
+++ python-psutil-7.1.0/debian/patches/0001-dont-depend-on-install-when-running-tests.patch	2026-08-15 12:05:08.000000000 +0200
@@ -3,12 +3,14 @@
 Subject: dont depend on install when running tests
 
 ---
- Makefile | 12 ------------
- 1 file changed, 12 deletions(-)
+ Makefile | 16 ----------------
+ 1 file changed, 16 deletions(-)
 
+diff --git a/Makefile b/Makefile
+index a57c4fe..6cc7410 100644
 --- a/Makefile
 +++ b/Makefile
-@@ -91,67 +91,51 @@ install-git-hooks:  ## Install GIT pre-c
+@@ -91,67 +91,51 @@ install-git-hooks:  ## Install GIT pre-commit hook.
  # ===================================================================
  
  test:  ## Run all tests. To run a specific test do "make test ARGS=psutil.tests.test_system.TestDiskAPIs"
diff -Nru python-psutil-7.1.0/debian/patches/0002-pass-PYTHONPATH-to-the-test-runner.patch python-psutil-7.1.0/debian/patches/0002-pass-PYTHONPATH-to-the-test-runner.patch
--- python-psutil-7.1.0/debian/patches/0002-pass-PYTHONPATH-to-the-test-runner.patch	2025-10-05 08:26:16.000000000 +0200
+++ python-psutil-7.1.0/debian/patches/0002-pass-PYTHONPATH-to-the-test-runner.patch	2026-08-15 12:05:08.000000000 +0200
@@ -6,6 +6,8 @@
  Makefile | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
 
+diff --git a/Makefile b/Makefile
+index 6cc7410..be62430 100644
 --- a/Makefile
 +++ b/Makefile
 @@ -4,13 +4,14 @@
diff -Nru python-psutil-7.1.0/debian/patches/0003-Handle-RLIM_INFINITY-on-Python-3.15-on-linux-2871.patch python-psutil-7.1.0/debian/patches/0003-Handle-RLIM_INFINITY-on-Python-3.15-on-linux-2871.patch
--- python-psutil-7.1.0/debian/patches/0003-Handle-RLIM_INFINITY-on-Python-3.15-on-linux-2871.patch	1970-01-01 01:00:00.000000000 +0100
+++ python-psutil-7.1.0/debian/patches/0003-Handle-RLIM_INFINITY-on-Python-3.15-on-linux-2871.patch	2026-08-15 12:05:08.000000000 +0200
@@ -0,0 +1,72 @@
+From: Giampaolo Rodola <[email protected]>
+Date: Fri, 17 Jul 2026 19:46:19 +0200
+Subject: Handle RLIM_INFINITY on Python 3.15 on linux (#2871)
+
+Origin: upstream, https://github.com/giampaolo/psutil/commit/b408cfc0a05266a0509ccbb13e253f2d2000ed9f
+Bug: https://github.com/giampaolo/psutil/issues/2871
+
+`Process.rlimit` returns `RLIM_INFINITY` as unsigned `2**64-1` instead
+of `-1` on Python 3.15+, which changed `resource.prlimit()` accordingly.
+psutil now maps it back to `psutil.RLIM_INFINITY` so the value stays
+consistent across Python versions.
+---
+ psutil/_pslinux.py         | 13 ++++++++++++-
+ psutil/tests/test_linux.py | 14 ++++++++++++++
+ 2 files changed, 26 insertions(+), 1 deletion(-)
+
+diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
+index b5095d4..3321654 100644
+--- a/psutil/_pslinux.py
++++ b/psutil/_pslinux.py
+@@ -83,6 +83,10 @@ PAGESIZE = cext_posix.getpagesize()
+ LITTLE_ENDIAN = sys.byteorder == 'little'
+ UNSET = object()
+ 
++# Python 3.15 changed resource.prlimit() to return RLIM_INFINITY as the
++# unsigned 2**64-1 instead of -1; used to map it back to -1.
++RLIM_INFINITY_UNSIGNED = cext_posix.RLIM_INFINITY & 0xFFFFFFFFFFFFFFFF
++
+ # "man iostat" states that sectors are equivalent with blocks and have
+ # a size of 512 bytes. Despite this value can be queried at runtime
+ # via /sys/block/{DISK}/queue/hw_sector_size and results may vary
+@@ -2213,7 +2217,14 @@ class Process:
+             try:
+                 if limits is None:
+                     # get
+-                    return resource.prlimit(self.pid, resource_)
++                    soft, hard = resource.prlimit(self.pid, resource_)
++                    # Python 3.15 returns RLIM_INFINITY as the unsigned
++                    # 2**64-1 instead of -1; map it back for consistency.
++                    if soft == RLIM_INFINITY_UNSIGNED:
++                        soft = cext_posix.RLIM_INFINITY
++                    if hard == RLIM_INFINITY_UNSIGNED:
++                        hard = cext_posix.RLIM_INFINITY
++                    return soft, hard
+                 else:
+                     # set
+                     if len(limits) != 2:
+diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
+index 5e325e5..7eb7469 100755
+--- a/psutil/tests/test_linux.py
++++ b/psutil/tests/test_linux.py
+@@ -2197,6 +2197,20 @@ class TestProcess(PsutilTestCase):
+         assert p._proc.create_time() != p._proc.create_time(monotonic=True)
+         assert p._get_ident()[1] == p._proc.create_time(monotonic=True)
+ 
++    def test_rlimit_infinity_normalized(self):
++        # Python 3.15 changed resource.prlimit() to return RLIM_INFINITY
++        # as the unsigned 2**64-1 instead of -1; psutil maps it back.
++        unsigned = 2**64 - 1
++        p = psutil.Process()
++        with mock.patch(
++            "psutil._pslinux.resource.prlimit",
++            return_value=(unsigned, unsigned),
++        ) as m:
++            soft, hard = p.rlimit(psutil.RLIMIT_FSIZE)
++            assert m.called
++        assert soft == psutil.RLIM_INFINITY
++        assert hard == psutil.RLIM_INFINITY
++
+ 
+ @pytest.mark.skipif(not LINUX, reason="LINUX only")
+ class TestProcessAgainstStatus(PsutilTestCase):
diff -Nru python-psutil-7.1.0/debian/patches/0004-tests-normalize-RLIM_INFINITY-from-resource-getrlimit.patch python-psutil-7.1.0/debian/patches/0004-tests-normalize-RLIM_INFINITY-from-resource-getrlimit.patch
--- python-psutil-7.1.0/debian/patches/0004-tests-normalize-RLIM_INFINITY-from-resource-getrlimit.patch	1970-01-01 01:00:00.000000000 +0100
+++ python-psutil-7.1.0/debian/patches/0004-tests-normalize-RLIM_INFINITY-from-resource-getrlimit.patch	2026-08-15 12:05:08.000000000 +0200
@@ -0,0 +1,25 @@
+From: Maximiliano Curia <[email protected]>
+Date: Sat, 15 Aug 2026 11:20:00 +0200
+Subject: tests: normalize RLIM_INFINITY from resource.getrlimit()
+
+---
+ psutil/tests/test_process.py | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
+index 264f3ed..c96f1f7 100755
+--- a/psutil/tests/test_process.py
++++ b/psutil/tests/test_process.py
+@@ -431,7 +431,11 @@ class TestProcess(PsutilTestCase):
+                 # number instead of -1. It looks like a bug with PyPy.
+                 if PYPY:
+                     continue
+-                assert p.rlimit(value) == resource.getrlimit(value)
++                limits = tuple(
++                    psutil.RLIM_INFINITY if x == resource.RLIM_INFINITY else x
++                    for x in resource.getrlimit(value)
++                )
++                assert p.rlimit(value) == limits
+             else:
+                 ret = p.rlimit(value)
+                 assert len(ret) == 2
diff -Nru python-psutil-7.1.0/debian/patches/series python-psutil-7.1.0/debian/patches/series
--- python-psutil-7.1.0/debian/patches/series	2025-10-05 08:26:16.000000000 +0200
+++ python-psutil-7.1.0/debian/patches/series	2026-08-15 12:05:08.000000000 +0200
@@ -1,2 +1,4 @@
 0001-dont-depend-on-install-when-running-tests.patch
 0002-pass-PYTHONPATH-to-the-test-runner.patch
+0003-Handle-RLIM_INFINITY-on-Python-3.15-on-linux-2871.patch
+0004-tests-normalize-RLIM_INFINITY-from-resource-getrlimit.patch
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEE+JIdOnQEyG4RNSIVxxl2mbKbIyoFAmqAa3QACgkQxxl2mbKb
Iypw2w//d3y6SpgcTQawgZfUBebkRPxlhCW7alYK/h3DJlfpAl3fV9sL6Y7fjlPQ
WG3ektBY9qQm8DEtKdaP1VhNudMKEtodJxUMrrQSJf8BppSCOo8NXGyWAdTv4c/w
v+ezxaH1XMeRCYPo9FPD4HnEXaISyYT2ZpDI9D/q/TMt2XBrWQm9nFc7G/z8AgqZ
wBC1Ps76Ol3P47Kwq0K20Wu7zkl8bx9AFOrv11IvNQDG3wBEFHat6sxwN6AHiOuM
vvNhJ4Qh7EE86Rnqr2xHW7rLI5XJRxlinz8GXqLmGhJOdCvRXhJ484E2JfGtp78C
4fyRLGt7VhctzZuPRL4NvTohSROdVE3X8kkGONIzpVRVNhT3xaZcSdNdGRPibHRL
BhwE6GpxtjfnIPGNtv2nGDUSYEYQ0tnP4NfE0+GrJCfmHEcwrxEmxWjdCTCQiTR9
Ca2E42UgMbR9MErncSgnhw6U1gAjHy0060mu/131uhFXD70N050GbyoGyiQPv0tn
hW2kxc1Jw8OC3lmpoBNDudEbHxJQ0dlfhdId/0tAzCYBnnXWQWfVLAlXpOxNhqyW
Hm4aUQw9Hg6e02hLZU0UONS+wLN0/gs7nMi0KWjylqGbpszpEHgT4FCwBV3KyyB7
sTUJKwZiemDuakl2sFkN6tjQtgZtphJ3YUa+avdcQf0Q3+CnGBc=
=Rm+D
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.