Backport test_resource fix from trunk to stop it crashing on Ubuntu

This commit is contained in:
Nick Coghlan 2008-02-11 11:31:24 +00:00
parent 3e5f8a6975
commit 0b5c17a9c3
1 changed files with 19 additions and 14 deletions

View File

@ -32,22 +32,27 @@ try:
except ValueError: except ValueError:
limit_set = 0 limit_set = 0
f = open(TESTFN, "wb") f = open(TESTFN, "wb")
try:
f.write("X" * 1024) f.write("X" * 1024)
f.flush()
try: try:
f.write("Y") f.write("Y")
f.flush() f.flush()
# On some systems (e.g., Ubuntu on hppa) the flush() # On some systems (e.g., Ubuntu on hppa) the flush()
# doesn't always cause the exception, but the close() # doesn't always cause the exception, but the close()
# does eventually. Try flushing several times in an attempt # does eventually. Try flushing several times in
# to ensure the file is really synced and the exception raised. # an attempt to ensure the file is really synced and
# the exception raised.
for i in range(5): for i in range(5):
time.sleep(.1) time.sleep(.1)
f.flush() f.flush()
f.close()
except IOError: except IOError:
if not limit_set: if not limit_set:
raise raise
if limit_set:
# Close will attempt to flush the byte we wrote
# Restore limit first to avoid getting a spurious error
resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
finally:
f.close() f.close()
finally: finally:
if limit_set: if limit_set: