generating stats from stdout on a regular interval

Gabriel Genellina gagsl-py2 at
Wed Mar 21 03:16:56 CET 2007

En Tue, 20 Mar 2007 22:45:16 -0300, russ <russell.sayers at>  

> Very new to Python - but excited to see what is possible - it sounds
> very suitable for a project of mine I need a little help with.
> I've got an executable which writes out data to stdout in a CSV sort
> of format - I'd like to grab the data from stdout and create stats
> from it at a regular interval, i.e. every 10 min.  Probably push the
> stats out to a CSV file.
> The popen2 module can read the stdout just like a file, and the csv
> module can handle the reading / writing.  How do I go about
> 'processing' the stdout every 10 min?

The executable is continuously writting data to stdout, right?
So your code will likely be reading that output inside a loop - just check  
using time.time() if the desired interval has elapsed.
Maybe you'd prefer using the subprocess module instead of popen2.

Gabriel Genellina

More information about the Python-list mailing list