Message9357
This test code looks fine, using with statements to ensure that files are being closed. To see if there's something else going on, I tried adding the following to get at the deterministic collection seen in CPython:
from test.test_support import gc_collect
...
def testDeleteZipTestZip(self):
src = self.src
target = self.target
shutil.copy(src, target)
with zipfile.ZipFile(target, 'r') as zipFile:
zipFile.testzip()
gc_collect()
os.remove(target)
self.assertEquals(os.path.isfile(target), False)
With that before each os.remove, things work just fine.
So presumably in shutil.copy (not so likely) or zipfile.testzip (more likely) there's a file that's being opened, but not explicitly closed. Under CPython, once the variable holding the reference goes out of scope, it gets immediately GCed. Under Jython, we can duplicate this behavior - if only for testing purposes - by invoking gc_collect.
Why does this work on Linux, and not on Windows? That's because in Windows, os.remove only works on files that are not currently open. On Linux, there's a ref counting scheme, so I can remove a file I have open, and it will go away upon close. |
|
Date |
User |
Action |
Args |
2015-01-08 04:35:11 | zyasoft | set | messageid: <1420691711.05.0.342962485006.issue2248@psf.upfronthosting.co.za> |
2015-01-08 04:35:11 | zyasoft | set | recipients:
+ zyasoft, tchen |
2015-01-08 04:35:11 | zyasoft | link | issue2248 messages |
2015-01-08 04:35:10 | zyasoft | create | |
|