os.popen and lengthy operations

Dmitry Teslenko dteslenko at gmail.com
Thu Sep 20 08:31:43 CEST 2007


Hello!
I'm using os.popen to perform lengthy operation such as building some
project from source.
It looks like this:
def execute_and_save_output( command, out_file, err_file):

import os

def execute_and_save_output( command, out_file, err_file):
	(i,o,e) = os.popen3( command )
	try:
		for line in o:
			out_file.write( line )

		for line in e:
			err_file.write( line )
	finally:
		i.close()
		o.close()
		e.close()

...
execute_and_save_output( '<some long to run command>', out_file, err_file)

Problem is that script hangs on operations that take long to execute
and have lots of output such as building scripts.



More information about the Python-list mailing list