Issue2248

classification
Title: os.remove fails after accessing zipfile on Windows
Type: Severity: normal
Components: Library Versions:
Milestone:
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: tchen, zyasoft
Priority: Keywords:

Created on 2015-01-08.00:12:09 by tchen, last changed 2015-02-08.06:04:40 by zyasoft.

Files
File name Uploaded Description Edit Remove
test.py tchen, 2015-01-08.00:12:09 unittests
Messages
msg9351 (view) Author: (tchen) Date: 2015-01-08.00:12:09
The attached code works fine on Linux but on Windows it fails with "OSError: unlink(): an unknown error occurred".
msg9357 (view) Author: Jim Baker (zyasoft) Date: 2015-01-08.04:35:10
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.
msg9501 (view) Author: Jim Baker (zyasoft) Date: 2015-02-08.06:04:40
There's really nothing to do here, so closing out.

We do have a related test failure, test_tarfile when run on Windows, but that's visible when run the regrtest
History
Date User Action Args
2015-02-08 06:04:40zyasoftsetstatus: open -> closed
resolution: accepted -> invalid
messages: + msg9501
2015-01-08 04:35:11zyasoftsetresolution: accepted
messages: + msg9357
nosy: + zyasoft
2015-01-08 00:12:09tchencreate