Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4a070a

Browse files
committed
Patch #551960: Add check for setrlimit() support
test_resource calls resource.setrlimit() to change the file size limits. This fails on Cygwin, which supports setrlimit() and getrlimit(), just not changing that particular setting. (The same would apply to any other platform that has those functions but not that particular feature.) Since getrlimit() works and setrlimit() can be used for other reasons, a check for ValueError was added to that part of the test.
1 parent 20b9135 commit e4a070a

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

Lib/test/test_resource.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,23 @@
2222
# pythonrun.c has been fixed to ignore that exception. If so, the
2323
# write() should return EFBIG when the limit is exceeded.
2424

25+
# At least one platform has an unlimited RLIMIT_FSIZE and attempts to
26+
# change it raise ValueError instead.
27+
2528
try:
26-
resource.setrlimit(resource.RLIMIT_FSIZE, (1024, max))
29+
try:
30+
resource.setrlimit(resource.RLIMIT_FSIZE, (1024, max))
31+
limit_set = 1
32+
except ValueError:
33+
limit_set = 0
2734
f = open(TESTFN, "wb")
2835
f.write("X" * 1024)
2936
try:
3037
f.write("Y")
3138
f.flush()
3239
except IOError:
33-
pass
40+
if not limit_set:
41+
raise
3442
f.close()
3543
os.unlink(TESTFN)
3644
finally:
@@ -40,9 +48,9 @@
4048
too_big = 10L**50
4149
try:
4250
resource.setrlimit(resource.RLIMIT_FSIZE, (too_big, max))
43-
except OverflowError:
51+
except (OverflowError, ValueError):
4452
pass
4553
try:
4654
resource.setrlimit(resource.RLIMIT_FSIZE, (max, too_big))
47-
except OverflowError:
55+
except (OverflowError, ValueError):
4856
pass

0 commit comments

Comments
 (0)