Author asvetlov
Recipients asvetlov, loewis
Date 2009-12-05.23:09:03
SpamBayes Score 3.34072e-12
Marked as misclassified No
Message-id <1260054545.67.0.113514795538.issue7443@psf.upfronthosting.co.za>
In-reply-to
Content
You right, problem is not in os.unlink (Windows call DeleteFile) itself.

I have TortoiseSVN (very popular Explorer extension to work with 
Subversion) installed. 
This tool run TSVNCache.exe process to update own data in background.
TSVNCache.exe receive NotifyChangeDirectory events for svn checkout 
folders. 
support.TESTFN is tempfile name in current working directory. If I try 
to run unittests from some folder from python checkout TSVNCache.exe get 
change notify and analyze it.

So, sometimes I can see race condition:
- python: os.unlink(file)
- TSVNCache.exe: get change event
- TSVNCache.exe: query changes
- python: open(file) - oops, TSVNCache.exe still processing notification 
and lock deleted file by holding opened handles to it.
According to MSDN for DeleteFile function:
The DeleteFile function marks a file for deletion on close. Therefore, 
the file deletion does not occur until the last handle to the file is 
closed. Subsequent calls to CreateFile to open the file fail with 
ERROR_ACCESS_DENIED.
We get exactly same.
- TSVNCache.exe finish of change update and release handle. File is 
actually deleted.

I see this situation in sysinternals Process Monitor tool.
Probability of race condition is tiny but non-zero. Intensive 
create/drop/create again sequences can catch this one.
History
Date User Action Args
2009-12-05 23:09:05asvetlovsetrecipients: + asvetlov, loewis
2009-12-05 23:09:05asvetlovsetmessageid: <1260054545.67.0.113514795538.issue7443@psf.upfronthosting.co.za>
2009-12-05 23:09:04asvetlovlinkissue7443 messages
2009-12-05 23:09:03asvetlovcreate