Re: os.path.getsize() on Windows



On Thu, 20 Mar 2008 13:42:22 +0000, Duncan Booth wrote:

Steven D'Aprano <steve@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

On Wed, 19 Mar 2008 12:34:34 +0000, Duncan Booth wrote:
By default Python on Windows allows you to open a file for reading
unless you specify a sharing mode which prevents it:

But the OP is talking about another process having opened the file for
WRITING, not reading. It's that other process that has exclusive
access, and the OP was trying to determine when it was safe to attempt
opening the file according to whether or not it was still growing.

No, unless the other process has specified that it wants exclusive
access there is nothing stopping his process also opening the file.
That's why he has to specify when he opens it that he wants exclusive
access: then it doesn't matter what the other process does, he won't be
able to open it until the other process has closed the file.


I think you're confused. Or possibly I'm confused. Or both.

It seems to me that you're assuming that the OP has opened the file for
reading first, and *then* another process comes along and wants to open
it for writing. That's not how I read his post: he's trying to open a
file for reading while it is already being written to by another process.
Asking for exclusive access when reading isn't going to make any
difference, because the other process has already opened the file for
writing.

I suppose it is conceivable that the other process might have opened the
file for non-exclusive writing, assuming that such a thing is even
possible, but how likely is that?



This all of course assumes that the other process writes the file in one
single atomic chunk. If it were to create it and then separately open
and write to it then all bets are off.

The OP is repeatedly polling the file to see when the size stops
increasing. Obviously a single atomic write is *not* taking place.


--
Steven
.



Relevant Pages

  • Re: os.path.getsize() on Windows
    ... unless the other process has specified that it wants exclusive access ... has to specify when he opens it that he wants exclusive access: ... the file is opened for reading. ...
    (comp.lang.python)
  • How to wait until the other end of a FIFO is reopened.
    ... descriptor of the writing end, but I cant' control how the libraries ... On the reading end, it's even worse: I can only pass the library the ... I get a SIGPIPE on the writing end before the reading end opens ...
    (comp.unix.programmer)
  • Re: fstream..
    ... if it does not exist then it opens file just for writing ... > creates a zero byte file and then closes, then i m able to use above ... > statement for writing and reading from it, m i doing it right, any ...
    (comp.lang.cpp)
  • Re: A bit of a problem with fopen()
    ... The fopenfunction opens the file whose name is the string pointed to by ... path and associates a stream with it. ... r+ Open for reading and writing. ... w Truncate file to zero length or create text file for writing. ...
    (comp.os.linux.development.apps)
  • Re: Reading a series of files
    ... I'd like to read a series of DICOM data files, ... I'm now writing a ... But I don't understand how I can finish reading ... If I specify the number of files in ...
    (comp.soft-sys.matlab)