Title: resource library (getrlimit, setrlimit) interprets resource limits as signed integers instead of unsigned · Issue #137044 · python/cpython · GitHub
Open Graph Title: resource library (getrlimit, setrlimit) interprets resource limits as signed integers instead of unsigned · Issue #137044 · python/cpython
X Title: resource library (getrlimit, setrlimit) interprets resource limits as signed integers instead of unsigned · Issue #137044 · python/cpython
Description: Bug report Bug description: as per System Calls Manual (man 2 setrlimit), rlim_t is an unsigned integer type in Python, reading the default hard limit (resource.getrlimit(resource.RLIMIT_CPU)) will return -1 executing this: resource.setr...
Open Graph Description: Bug report Bug description: as per System Calls Manual (man 2 setrlimit), rlim_t is an unsigned integer type in Python, reading the default hard limit (resource.getrlimit(resource.RLIMIT_CPU)) will...
X Description: Bug report Bug description: as per System Calls Manual (man 2 setrlimit), rlim_t is an unsigned integer type in Python, reading the default hard limit (resource.getrlimit(resource.RLIMIT_CPU)) will...
Opengraph URL: https://github.com/python/cpython/issues/137044
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"resource library (getrlimit, setrlimit) interprets resource limits as signed integers instead of unsigned","articleBody":"# Bug report\n\n### Bug description:\n\n* as per System Calls Manual (`man 2 setrlimit`), `rlim_t` is an **unsigned** integer type\n* in Python, reading the default hard limit (`resource.getrlimit(resource.RLIMIT_CPU)`) will return `-1`\n* executing this:\n\n``` python3\nresource.setrlimit(resource.RLIMIT_CPU, (-2, -2))\nos.system(\"ulimit -t\")\n```\nreturns `18446744073709551614`\n * executing `ulimit -t 18446744073709551614`, then in python3 `resource.getrlimit(resource.RLIMIT_CPU)`, will return `-2`\n\nThis behaviour is very weird and will cause the following rather useful and common snippet to fail:\n``` python3\n_, hardlimit = resource.getrlimit(resource.RLIMIT_CPU)\nrlimit = (min(timelimit, hardlimit), hardlimit)\nresource.setrlimit(resource.RLIMIT_CPU, rlimit)\n```\n\nThere happens to exist the following workaround:\n``` python3\n_, hardlimit = resource.getrlimit(resource.RLIMIT_CPU)\nsoftlimit = ctypes.c_long(min(seconds, ctypes.c_ulong(hardlimit).value)).value\nrlimit = (softlimit, hardlimit)\nresource.setrlimit(resource.RLIMIT_CPU, rlimit)\n```\nbut it just feels extremely hacky to do things like this and I believe a lot of programmers end in this trap.\nEspecially that when you handle the `-1` case specially (as it is mentioned in man, that \"RLIM_INFINITY typically is the same as -1\"), it still fails with other negative values like `-2`.\n\n### CPython versions tested on:\n\n3.15\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-137338\n* gh-137506\n* gh-137507\n* gh-137511\n* gh-137938\n* gh-137941\n* gh-137954\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/ArturBieniek4","@type":"Person","name":"ArturBieniek4"},"datePublished":"2025-07-23T14:12:08Z","url":"https://github.com/python/cpython/issues/137044"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:36b40607-bdfc-6f79-b4f6-7a347ef48bd9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEC8:A71F9:36034DC:445A180:6B021B67 |
| html-safe-nonce | 89ee102fe289b6d8e742a16bbf92b4c037b8b3c81bf6040384daa5db3d959cc6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUM4OkE3MUY5OjM2MDM0REM6NDQ1QTE4MDo2QjAyMUI2NyIsInZpc2l0b3JfaWQiOiI0NTY2NzU5NjczNDQxODgyNjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a9c64b11bbd982823bd5fdedf7ad265c3f4a3d7b18a502f2c5b678a4c4867128 |
| hovercard-subject-tag | issue:3256561701 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/137044/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3fce99111a56873c31b80cab7c31c52229ac654e74ddbc1cea34bf73f59ee417/python/cpython/issues/137044 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3fce99111a56873c31b80cab7c31c52229ac654e74ddbc1cea34bf73f59ee417/python/cpython/issues/137044 |
| og:image:alt | Bug report Bug description: as per System Calls Manual (man 2 setrlimit), rlim_t is an unsigned integer type in Python, reading the default hard limit (resource.getrlimit(resource.RLIMIT_CPU)) will... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ArturBieniek4 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width