PDA

View Full Version : pyqt 4: readyReadStandardOutput singal only emits after subprocess completes



FrancisKwok
12th August 2009, 22:22
Hello,

I'm new to Qt and I'm trying to redirect the stdout/stderr from a python script to a TextBroswer window. The problem I'm having is that it seem like the readyReadStandardOutput singal only emits after subprocess completes. I would like it to emit whenever there is new data so it looks like it updated in real-time as the script runs.

here's some code snipets:


def runScript(self):
process = QProcess()
self.RunningProcess = process
self.RunningProcess.setProcessChannelMode(QProcess .MergedChannels)
self.RunningProcess.closeWriteChannel()
command = "C:\\Python25\\python.exe TestOptparse.py"
self.connect(self.RunningProcess, SIGNAL("readyReadStandardOutput()"), self.readOutput)
self.connect(self.RunningProcess, SIGNAL("readyReadStandardError()"), self.readOutput)
self.RunningProcess.start(command)

def readOutput(self):
string = ""
bytearray = self.RunningProcess.readAllStandardOutput()

if not bytearray.isEmpty():
string = str(QString(bytearray))

self.LoggerWidget.append(string)

Please help!!

Francis

wagmare
13th August 2009, 05:57
readyReadStandardOutput singal only emits after subprocess completes .. i once faced this problem ..


it's a problem of an incorrectly setup buffering method... and
you won't be able to solve this from within your calling program.
Either "patch" the program you are calling to use line buffering --
setlinebuf(stdout) -- or use fflush(stdout) every now and then in this
program. If you can't do this, then there's no way to solve it.

It's NOT a problem of QProcess or anything you could solve by any trickery
here... I have similar issues with some of the programs that I call from some
of my apps and there's no way around it (at least no platform independent
one).
ex: i am using linux to run an external system call glxgears in QProcess and i get output after ten minutes only or when the buffer filled completly ..
i try this one "glxgears | less" and find the problem in buffer flush

FrancisKwok
14th August 2009, 19:54
Thank You! That helped a lot. If somebody else has this problem with Python script processes, you can look here for the solution.

http://stackoverflow.com/questions/107705/python-output-buffering