0001 import os 0002 import resource 0003 0004 from test.test_support import TESTFN 0005 0006 # This test is checking a few specific problem spots. RLIMIT_FSIZE 0007 # should be RLIM_INFINITY, which will be a really big number on a 0008 # platform with large file support. On these platforms, we need to 0009 # test that the get/setrlimit functions properly convert the number to 0010 # a C long long and that the conversion doesn't raise an error. 0011 0012 try: 0013 cur, max = resource.getrlimit(resource.RLIMIT_FSIZE) 0014 except AttributeError: 0015 pass 0016 else: 0017 print resource.RLIM_INFINITY == max 0018 resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max)) 0019 0020 # Now check to see what happens when the RLIMIT_FSIZE is small. Some 0021 # versions of Python were terminated by an uncaught SIGXFSZ, but 0022 # pythonrun.c has been fixed to ignore that exception. If so, the 0023 # write() should return EFBIG when the limit is exceeded. 0024 0025 # At least one platform has an unlimited RLIMIT_FSIZE and attempts to 0026 # change it raise ValueError instead. 0027 0028 try: 0029 try: 0030 resource.setrlimit(resource.RLIMIT_FSIZE, (1024, max)) 0031 limit_set = 1 0032 except ValueError: 0033 limit_set = 0 0034 f = open(TESTFN, "wb") 0035 f.write("X" * 1024) 0036 try: 0037 f.write("Y") 0038 f.flush() 0039 except IOError: 0040 if not limit_set: 0041 raise 0042 f.close() 0043 os.unlink(TESTFN) 0044 finally: 0045 resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max)) 0046 0047 # And be sure that setrlimit is checking for really large values 0048 too_big = 10L**50 0049 try: 0050 resource.setrlimit(resource.RLIMIT_FSIZE, (too_big, max)) 0051 except (OverflowError, ValueError): 0052 pass 0053 try: 0054 resource.setrlimit(resource.RLIMIT_FSIZE, (max, too_big)) 0055 except (OverflowError, ValueError): 0056 pass 0057
Generated by PyXR 0.9.4