Message9357

Author zyasoft
Recipients tchen, zyasoft
Date 2015-01-08.04:35:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1420691711.05.0.342962485006.issue2248@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-01-08 04:35:11zyasoftsetmessageid: <1420691711.05.0.342962485006.issue2248@psf.upfronthosting.co.za>
2015-01-08 04:35:11zyasoftsetrecipients: + zyasoft, tchen
2015-01-08 04:35:11zyasoftlinkissue2248 messages
2015-01-08 04:35:10zyasoftcreate