Problems writing to file

Gary Herron gherron at islandtraining.com
Tue Mar 21 16:01:39 EST 2006


Bernard Lebel wrote:

>Hello,
>
>I have this strange problem. I have written a program that writes a
>log to a log file.
>
>To start the program (I'm on Linux Fedora Core 3), I used a service.
>This service runs a bash file, wich in turn runs the Python top
>program file.
>
>Sooner or later the program stops writing to the log file. I have
>absolutely no clue why would that happen. Since the output of the
>Python program is not redirected other than to this log file, I have
>no idea why it's doing this. But the Python process appears still
>alive and well!
>
>But the strange thing is that if I run the program directly from a
>bash shell, no problem whatsoever, the programs runs smoothly and
>never stops writing to the file, until I kill it.
>
>
>Any suggestion?
>
>
>
>Thanks in advance
>Bernard
>  
>
Perhaps ...

Output is normally buffered in memory until some threshhold is reached, 
at which point the whole buffer is written, and the process repeats. If 
your output quantity is small, and your impatience is high, you may be 
declaring failure before the buffer fills and triggers a write. The 
solution would be to call flush on the output file after each write (or 
perhaps just wait more patiently).

If the output is voluminous, then it's probably something else ... but I 
don't know what. Perhpas you could post your code.

Gary Herron




More information about the Python-list mailing list