SOLVED: Can os.remove followed by os.path.isfile disagree?

Paul Paterson ppaterson at gmail.com
Wed Jun 6 14:58:41 EDT 2007


On Jun 6, 12:30 pm, "Roger Upole" <rup... at hotmail.com> wrote:
> ppater... at gmail.com wrote:
> > Can os.path.isfile(x) ever return True after os.remove(x) has
> > successfully completed? (Windows 2003,  Python 2.3)
>
> Yes.  If another application has opened the file with FILE_SHARE_DELETE,
> os.remove succeeds but the file doesn't actually disappear until the last open
> handle to it is closed.
>

Roger,

Thanks - you've hit the nail on the head. This is the final piece of
the puzzle and I've now been able to reproduce the problem!

The cause is ...

- a TSVCache.exe (Tortoise SVN) process is scanning the file with
FILE_SHARE_DELETE access at the moment that the os.remove occurs
- this causes os.remove to return but the file is still there while
the scan completes
- next, os.path.isfile returns True and the app raises an exception
- a short while later the scan is complete and Windows deletes the
file

Thanks to everyone who responded - I didn't expect to be able to get
to the bottom of this so quickly!

Thanks,

Paul




More information about the Python-list mailing list