blob: 1293833e307fbb9873af7af2266325bd0b524f72 [file] [log] [blame]
Jeremy Hylton74ce77f2002-04-23 20:21:22 +00001import os
2import resource
3
4from test_support import TESTFN
5
6# This test is checking a few specific problem spots. RLIMIT_FSIZE
7# should be RLIM_INFINITY, which will be a really big number on a
8# platform with large file support. On these platforms, we need to
9# test that the get/setrlimit functions properly convert the number to
10# a C long long and that the conversion doesn't raise an error.
11
12try:
13 cur, max = resource.getrlimit(resource.RLIMIT_FSIZE)
14except AttributeError:
15 pass
16else:
17 print resource.RLIM_INFINITY == max
18 resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
19
20# Now check to see what happens when the RLIMIT_FSIZE is small. Some
21# versions of Python were terminated by an uncaught SIGXFSZ, but
22# pythonrun.c has been fixed to ignore that exception. If so, the
23# write() should return EFBIG when the limit is exceeded.
24
25try:
26 resource.setrlimit(resource.RLIMIT_FSIZE, (1024, max))
27 f = open(TESTFN, "wb")
28 f.write("X" * 1024)
29 try:
30 f.write("Y")
31 f.flush()
32 except IOError:
33 pass
34 f.close()
35 os.unlink(TESTFN)
36finally:
37 resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
38
39# And be sure that setrlimit is checking for really large values
40too_big = 10L**50
41try:
42 resource.setrlimit(resource.RLIMIT_FSIZE, (too_big, max))
43except OverflowError:
44 pass
45try:
46 resource.setrlimit(resource.RLIMIT_FSIZE, (max, too_big))
47except OverflowError:
48 pass