PDA

View Full Version : Flush buffer for QProcess in PyQt5



hannahpatellis
4th November 2016, 02:19
Hi everyone!

I have a Python 3.4 app using the PyQt5 framework and I'm having an issue.

I setup a QProcess:


def listenToServer(self, MainWindow):
self.ws = QtCore.QProcess(self)
self.ws.start("python3 /home/pi/scara_panel/ws.py")
self.ws.readyReadStandardOutput.connect(self.proce ssServer)

And it calls this function:


def processServer(self):
income = str(self.ws.readAllStandardOutput())
print(income)

On a desktop, it works fine. It flows into to the app. However, when the program is run on a Raspberry Pi, it only displays what its read once the script ws.py terminates.

I've read that this has to do with output buffering in Python. I've tried things like adding the -u flag, but no dice. Any suggestions on how to clear this buffer when using readAllStandardOutput()?

I've tried implementing a few things from http://stackoverflow.com/questions/107705/disable-output-buffering but nothing seems to fix the issue.

Any help is appreciated!

anda_skoa
4th November 2016, 10:01
Strange, as usually there is very little to no difference between running on desktop Linux and on embedded Linux, especially on the Pi as this is often desktop Linux, just for ARM (e.g. Rasphian).

Have you tried the "-u" switch with the better QProcess start() overload?
The one that takes the program to run and the arguments as a list?

Cheers,
_

hannahpatellis
4th November 2016, 14:10
Strange, as usually there is very little to no difference between running on desktop Linux and on embedded Linux, especially on the Pi as this is often desktop Linux, just for ARM (e.g. Rasphian).

Have you tried the "-u" switch with the better QProcess start() overload?
The one that takes the program to run and the arguments as a list?

Cheers,
_

That did the trick! Thank you so much, I can't believe I hadn't thought of that!