Re: polling for output from a subprocess module



jakub.hrozek@xxxxxxxxx wrote:

try:
test = Popen(test_path,
stdout=PIPE,
stderr=PIPE,
close_fds=True,
env=test_environ)

while test.poll() == None:
ready = select.select([test.stderr], [], [])

if test.stderr in ready[0]:
t_stderr_new = test.stderr.readlines()
if t_stderr_new != []:
print "STDERR:", "\n".join(t_stderr_new)
t_stderr.extend(t_stderr_new)
[...]
The problem is, that it seems that all the output from the subprocess
seems to be coming at once. Do I need to take a different approach?

The readlines() method will read until it reaches end of file (or
an error occurs), not just what is available at the moment. You
can see that for your self by running:

$ python -c 'import sys; print sys.stdin.readlines()'

The call to sys.stdin.readlines() will not return until you press
Ctrl-D (or, I think, Ctrl-Z if you are using MS-Windows).

However, the os.read() function will only read what is currently
available. Note, though, that os.read() does not do line-based
I/O, so depending on the timing you can get incomplete lines, or
multiple lines in one read.


--
Thomas Bellman, Lysator Computer Club, Linköping University, Sweden
"Adde parvum parvo magnus acervus erit" ! bellman @ lysator.liu.se
(From The Mythical Man-Month) ! Make Love -- Nicht Wahr!
.



Relevant Pages

  • Re: polling for output from a subprocess module
    ... I/O, so depending on the timing you can get incomplete lines, or ... multiple lines in one read. ... Reading ...
    (comp.lang.python)
  • Re: Epistemology 201: The Science of Science
    ... Then Daryl's definition above is incomplete. ... mathematicians define multiple in absolute terms. ... -- "I know that most men, including those at ease with problems of the greatest complexity, can seldom accept even the simplest and most obvious truth if it be such as would oblige them to admit the falsity of conclusions which they have delighted in explaining to colleagues, which they have proudly taught to others, and which they have woven, thread by thread, into the fabric of their lives." ...
    (sci.math)
  • Re: Epistemology 201: The Science of Science
    ... Then Daryl's definition above is incomplete. ... mathematicians define multiple in absolute terms. ... -- "I know that most men, including those at ease with problems of the greatest complexity, can seldom accept even the simplest and most obvious truth if it be such as would oblige them to admit the falsity of conclusions which they have delighted in explaining to colleagues, which they have proudly taught to others, and which they have woven, thread by thread, into the fabric of their lives." ...
    (sci.cognitive)
  • Re: Epistemology 201: The Science of Science
    ... Then Daryl's definition above is incomplete. ... mathematicians define multiple in absolute terms. ... -- "I know that most men, including those at ease with problems of the greatest complexity, can seldom accept even the simplest and most obvious truth if it be such as would oblige them to admit the falsity of conclusions which they have delighted in explaining to colleagues, which they have proudly taught to others, and which they have woven, thread by thread, into the fabric of their lives." ...
    (sci.physics)
  • Re: Suppress for form submission?
    ... incomplete, show the form again. ... up to the browser what to do with forms that have multiple submit ... clickable object to do the submit bit..? ...
    (comp.lang.php)