Check whether file is being written to

Seebs usenet-nospam at seebs.net
Thu Sep 23 11:20:07 EDT 2010


On 2010-09-23, loial <jldunn2000 at gmail.com> wrote:
> How can I check whether a file is being written to by another process
> before I access it?

You mean "written to" or "open for possible writing"?

It may be possible (with sufficient privileges) to determine that a
file has been opened for writing.  I don't think you can detect
being-written-to.

More importantly, though, the question is irrelevant, because even if
you absolutely, conclusively, prove that a file is not open nor being
written to, before your next machine instruction loads, the file could
be opened and rewritten multiple times by whole new processes that weren't
even running when you checked.

I suggest you look into advisory locks.

-s
-- 
Copyright 2010, all wrongs reversed.  Peter Seebach / usenet-nospam at seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.



More information about the Python-list mailing list