Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

resource library (getrlimit, setrlimit) interprets resource limits as signed integers instead of unsigned #137044

Closed
Assignees
serhiy-storchaka
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@ArturBieniek4

Description

@ArturBieniek4

Bug report

Bug description:

  • as per System Calls Manual (man 2 setrlimit),rlim_t is anunsigned integer type
  • in Python, reading the default hard limit (resource.getrlimit(resource.RLIMIT_CPU)) will return-1
  • executing this:
resource.setrlimit(resource.RLIMIT_CPU, (-2,-2))os.system("ulimit -t")

returns18446744073709551614

  • executingulimit -t 18446744073709551614, then in python3resource.getrlimit(resource.RLIMIT_CPU), will return-2

This behaviour is very weird and will cause the following rather useful and common snippet to fail:

_,hardlimit=resource.getrlimit(resource.RLIMIT_CPU)rlimit= (min(timelimit,hardlimit),hardlimit)resource.setrlimit(resource.RLIMIT_CPU,rlimit)

There happens to exist the following workaround:

_,hardlimit=resource.getrlimit(resource.RLIMIT_CPU)softlimit=ctypes.c_long(min(seconds,ctypes.c_ulong(hardlimit).value)).valuerlimit= (softlimit,hardlimit)resource.setrlimit(resource.RLIMIT_CPU,rlimit)

but it just feels extremely hacky to do things like this and I believe a lot of programmers end in this trap.
Especially 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.

CPython versions tested on:

3.15

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp