[Python-Dev] windows file closing race condition?

Chris Withers chris at simplistix.co.uk
Fri Sep 6 07:50:07 CEST 2013


Hi All,

Continuous testing is a wonderful thing when it comes to finding weird 
edge case problems, like this one:

http://jenkins.simplistix.co.uk/job/testfixtures-tox/COMPONENTS=zc,PYTHON=3.3,label=windows/149/testReport/junit/testfixtures.tests.test_tempdirectory/TempDirectoryTests/test_check_all_tuple/

   File 
"C:\Jenkins\workspace\testfixtures-tox\e8666d4e\.tox\3.3-zc\lib\site-packages\testfixtures\tempdirectory.py", 
line 323, in __exit__
     self.cleanup()
   File 
"C:\Jenkins\workspace\testfixtures-tox\e8666d4e\.tox\3.3-zc\lib\site-packages\testfixtures\tempdirectory.py", 
line 78, in cleanup
     rmtree(self.path)
   File 
"C:\Jenkins\workspace\testfixtures-tox\e8666d4e\.tox\3.3-zc\lib\shutil.py", 
line 460, in rmtree
     return _rmtree_unsafe(path, onerror)
   File 
"C:\Jenkins\workspace\testfixtures-tox\e8666d4e\.tox\3.3-zc\lib\shutil.py", 
line 362, in _rmtree_unsafe
     _rmtree_unsafe(fullname, onerror)
   File 
"C:\Jenkins\workspace\testfixtures-tox\e8666d4e\.tox\3.3-zc\lib\shutil.py", 
line 371, in _rmtree_unsafe
     onerror(os.rmdir, path, sys.exc_info())
   File 
"C:\Jenkins\workspace\testfixtures-tox\e8666d4e\.tox\3.3-zc\lib\shutil.py", 
line 369, in _rmtree_unsafe
     os.rmdir(path)
OSError: [WinError 145] The directory is not empty: 
'c:\\users\\jenkins\\appdata\\local\\temp\\tmpkeg4d7\\a'

I'm 99% certain my code is correct here, the only place I open files for 
writing in that directory is here:

https://github.com/Simplistix/testfixtures/blob/master/testfixtures/tempdirectory.py#L275

So, from my perspective, I'm either looking at a bug in shutil.rmtree 
(which would be trying to delete a directory before deleting its content 
or failing to delete a file but ignoring an error) or the file object, 
when being used as a context manager, going through __exit__ without 
closing the file and releasing the handle.

This happens very infrequently, the OS is Windows 7 and the filesystem 
is NTFS, if that helps...

Any ideas?

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
            - http://www.simplistix.co.uk


More information about the Python-Dev mailing list