Can os.remove followed by os.path.isfile disagree?
Diez B. Roggisch
deets at nospam.web.de
Wed Jun 6 11:37:10 EDT 2007
ppaterson at gmail.com wrote:
> Can os.path.isfile(x) ever return True after os.remove(x) has
> successfully completed? (Windows 2003, Python 2.3)
>
> We had a couple of failures in a server application that we cannot yet
> reproduce in a simple case. Analysis of the code suggests that the
> only possible explanation is that the following occurs,
>
> os.remove(x)
> .... stuff
> if os.path.isfile(x):
> raise "Ooops, how did we get here?"
> file(x, "wb").write(content)
>
> We end up in the raise. By the time we get to look at the system the
> file is actually gone, presumably because of the os.remove.
>
> The "stuff" is a handful of lines of code which don't take any
> significant time to perform. There are no "try" blocks to mask a
> failure in the os.remove call.
>
>
> The application is multithreaded so it is possible that another thread
> writes to the file between the "remove" and the "isfile", but at the
> end of the failure the file is actually not on the filesystem and I
> don't believe there is a way that the file could be removed again in
> this scenario.
Is the file on a network drive by any chance?
Diez
More information about the Python-list
mailing list