[Tutor] logic for a tree like structure
jeff at drinktomi.com
Sun Dec 9 01:13:19 CET 2007
Pipes and IO channels are buffered. The buffers are much larger than
the amount of information you are writing to them, so they're never
flushed while the program is running. The child program completes, the
IO channel closes, and it flushes out the output.
My advice is to forget about all the file descriptor and pipes stuff.
incremental IO from them via the subprocess module (or any standard IO
module) is painful. You're probably better off getting the nonstandard
pexpect module and using that instead.
Here's your program using pexpect.
cmd = pexpect.spawn('./writer.py')
# wait for the end of the line or ten seconds
# get output preceding the EOF matched above
line = cmd.before
print '[main]', line
print "No output received for ten seconds"
if __name__ == '__main__':
- Jeff Younker - jeff at drinktomi.com -
More information about the Tutor