os.path.getsize() on Windows
steve at REMOVE-THIS-cybersource.com.au
Thu Mar 20 23:47:15 CET 2008
On Thu, 20 Mar 2008 13:42:22 +0000, Duncan Booth wrote:
> Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> 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
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.
More information about the Python-list