[Chicago] Popen/subprocess/Poll Question.
Samir Faci
samir at esamir.com
Thu Jul 22 16:55:24 CEST 2010
I'm sure this is something fairly silly I'm overlooking, but I've been
spending too much time on this... so I figured I should ask the powers
that be.
I'm running a process that's usually takes a while.... (in the best
case scenario a few hours... going on days occasionally)
I'm presuming I need to spawn a thread for the process so it doesn't block.
So I have something like this:
class testit(Thread):
def __init__ (self,cmd):
Thread.__init__(self)
self.cmd = cmd
self.p = sub.Popen(shlex.split(self.cmd), stdout=sub.PIPE,
stderr=sub.PIPE)
def run(self):
out,err = self.p.communicate()
print out
print err
def getProcess(self):
return self.p
current = testit("watch -n 5 date")
proc = current.getProcess
#### insert useful code here
current.start()
current.join()
Now, what I'm trying to accomplish is to have it print its output to a
screen AND let me capture its output. I'd like to see the output.
I'd also like to see the output as its processing, not capture it, and
print it to screen and then write to file.
I think I need to poll it before starting the process, and register an
event so whenever stdout changes, I can pull that information and push
write to file.
Though the whole events/polling isn't making much sense to me right
now. Any hints?
--
Samir Faci
*insert title*
fortune | cowsay -f /usr/share/cows/tux.cow
More information about the Chicago
mailing list