Using communicate is basically going to block until the process is done. You can use a tempfile and read the temp file at some interval to print to screen, then fseek(0) at the end to get the contents of the file. Also, if you use PIPE it goes to memory which can really screw you up if you have a lot of output. <div>
<br></div><div>To use poll you basically have to check it periodically. I do this in twisted with a reactor.callLater(1, blah.check_process()) . You can do the same with a while loop with a sleep in it.</div><div><br></div>
<div>Dan</div><div><br></div><div><br></div><div><br><div class="gmail_quote">On Thu, Jul 22, 2010 at 9:55 AM, Samir Faci <span dir="ltr">&lt;<a href="mailto:samir@esamir.com">samir@esamir.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I&#39;m sure this is something fairly silly I&#39;m overlooking, but I&#39;ve been<br>
spending too much time on this... so I figured I should ask the powers<br>
that be.<br>
<br>
I&#39;m running a process that&#39;s usually takes a while.... (in the best<br>
case scenario a few hours... going on days occasionally)<br>
<br>
I&#39;m presuming I need to spawn a thread for the process so it doesn&#39;t block.<br>
<br>
So I have something like this:<br>
<br>
class testit(Thread):<br>
   def __init__ (self,cmd):<br>
      Thread.__init__(self)<br>
      self.cmd = cmd<br>
      self.p = sub.Popen(shlex.split(self.cmd), stdout=sub.PIPE,<br>
stderr=sub.PIPE)<br>
   def run(self):<br>
      out,err = self.p.communicate()<br>
      print out<br>
      print err<br>
   def getProcess(self):<br>
       return self.p<br>
<br>
current = testit(&quot;watch -n 5 date&quot;)<br>
proc = current.getProcess<br>
<br>
#### insert useful code here<br>
<br>
current.start()<br>
current.join()<br>
<br>
<br>
Now, what I&#39;m trying to accomplish is to have it print its output to a<br>
screen AND let me capture its output.  I&#39;d like to see the output.<br>
I&#39;d also like to see the output as its processing, not capture it, and<br>
print it to screen and then write to file.<br>
<br>
I think I need to poll it before starting the process, and register an<br>
event so whenever stdout changes, I can pull that information and push<br>
write to file.<br>
Though the whole events/polling isn&#39;t making much sense to me right<br>
now.  Any hints?<br>
<font color="#888888"><br>
<br>
--<br>
Samir Faci<br>
*insert title*<br>
fortune | cowsay -f /usr/share/cows/tux.cow<br>
_______________________________________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org">Chicago@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/mailman/listinfo/chicago</a><br>
</font></blockquote></div><br></div>