Commit 0b5c17a9 authored by Nick Coghlan's avatar Nick Coghlan

Backport test_resource fix from trunk to stop it crashing on Ubuntu

parent 3e5f8a69
...@@ -32,23 +32,28 @@ try: ...@@ -32,23 +32,28 @@ try:
except ValueError: except ValueError:
limit_set = 0 limit_set = 0
f = open(TESTFN, "wb") f = open(TESTFN, "wb")
f.write("X" * 1024)
f.flush()
try: try:
f.write("Y") f.write("X" * 1024)
f.flush() try:
# On some systems (e.g., Ubuntu on hppa) the flush() f.write("Y")
# doesn't always cause the exception, but the close()
# does eventually. Try flushing several times in an attempt
# to ensure the file is really synced and the exception raised.
for i in range(5):
time.sleep(.1)
f.flush() f.flush()
# On some systems (e.g., Ubuntu on hppa) the flush()
# doesn't always cause the exception, but the close()
# does eventually. Try flushing several times in
# an attempt to ensure the file is really synced and
# the exception raised.
for i in range(5):
time.sleep(.1)
f.flush()
except IOError:
if not limit_set:
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()
except IOError:
if not limit_set:
raise
f.close()
finally: finally:
if limit_set: if limit_set:
resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max)) resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment