get the size of a dynamically changing file fast ?

Stef Mientki stef.mientki at gmail.com
Tue Jan 22 22:35:45 CET 2008


Mike Driscoll wrote:
> On Jan 17, 3:56 pm, Stef Mientki <stef.mien... at gmail.com> wrote:
>   
>> hello,
>>
>> I've a program (not written in Python) that generates a few thousands
>> bytes per second,
>> these files are dumped in 2 buffers (files), at in interval time of 50 msec,
>> the files can be read by another program, to do further processing.
>>
>> A program written in VB or delphi can handle the data in the 2 buffers
>> perfectly.
>> Sometimes Python is also able to process the data correctly,
>> but often it can't :-(
>>
>> I keep one of the files open en test the size of the open datafile each
>> 50 msec.
>> I have tried
>>     os.stat ( ....) [ ST_SIZE]
>>     os.path.getsize ( ... )
>> but they both have the same behaviour, sometimes it works, and the data
>> is collected each 50 .. 100 msec,
>> sometimes 1 .. 1.5 seconds is needed to detect a change in filesize.
>>
>> I'm using python 2.4 on winXP.
>>
>> Is there a solution for this problem ?
>>
>> thanks,
>> Stef Mientki
>>     
>
> Tim Golden has a method to watch for changes in a directory on his
> website:
>
> http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html
>
> This old post also mentions something similar:
>
> http://mail.python.org/pipermail/python-list/2007-October/463065.html
>
> And here's a cookbook recipe that claims to do it as well using
> decorators:
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/426620
>
> Hopefully that will get you going.
>
> Mike
>   
thanks Mike,
sorry for the late reaction.
I've it working perfect now.
After all, os.stat works perfectly well,
the problem was in the program that generated the file with increasing 
size,
by truncating it after each block write, it apperently garantees that 
the file is flushed to disk and all problems are solved.

cheers,
Stef Mientki





More information about the Python-list mailing list