diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2008-02-11 11:31:24 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2008-02-11 11:31:24 (GMT) |
commit | 0b5c17a9c3055491b654bca482e3b1805610ac3d (patch) | |
tree | 37e7626f0068d708b73e5415bfa0d0cddf5d6917 | |
parent | 3e5f8a6975cb7f7c3dc9f84686f27c49bc4aa75a (diff) | |
download | cpython-0b5c17a9c3055491b654bca482e3b1805610ac3d.zip cpython-0b5c17a9c3055491b654bca482e3b1805610ac3d.tar.gz cpython-0b5c17a9c3055491b654bca482e3b1805610ac3d.tar.bz2 |
Backport test_resource fix from trunk to stop it crashing on Ubuntu
-rw-r--r-- | Lib/test/test_resource.py | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/Lib/test/test_resource.py b/Lib/test/test_resource.py index c86735a..d40276f 100644 --- a/Lib/test/test_resource.py +++ b/Lib/test/test_resource.py @@ -32,23 +32,28 @@ try: except ValueError: limit_set = 0 f = open(TESTFN, "wb") - f.write("X" * 1024) - f.flush() try: - f.write("Y") - 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.write("X" * 1024) + try: + f.write("Y") 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() - except IOError: - if not limit_set: - raise - f.close() finally: if limit_set: resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max)) |