I experienced this bug in a more complex application I am developing. I execute a python server program and want to read the first data available. And then close it. I do that to validate some settings from the server.
My problem boils down to:
- QProcess.waitForReadyRead() doesn’t return and timeouts, it’s supposed to return True very quickly
- It used to work, I rollbacked to an older revision to try to find what caused this to break now, but it’s always there now, I really tried everything I could think of, so I want to know if it’s a normal problem or maybe something that would only affect me and caused by my environment.
This is the test I wrote to show the problem, when I execute it, the 3 first checks return the data immediately, but the last one timeouts and I get no data.
This is certainly not logical. In the test I used wait, in my server it’s just a select-like function, it’s implemented with base modules in python.
from PyQt4 import QtCore
#FILE: 1.py
#print 'TEST'
#FILE: 2.py
# import time
#print 'TEST'
#time.sleep(100)
#FILE: 1.sh
# echo 'TEST'
#FILE: 2.sh
# echo 'TEST'
# sleep 100
proc0= QtCore.QProcess()
proc0.start('sh', ['./1.sh'])
proc0.waitForStarted()
proc0.waitForReadyRead(10000)
output0 = proc0.readAll()
proc1= QtCore.QProcess()
proc1.start('sh', ['./2.sh'])
proc1.waitForStarted()
proc1.waitForReadyRead(10000)
output1 = proc1.readAll()
proc2= QtCore.QProcess()
proc2.start('python', ['./1.py'])
proc2.waitForStarted()
proc2.waitForReadyRead(10000)
output2 = proc2.readAll()
proc3= QtCore.QProcess()
proc3.start('python', ['./2.py'])
proc3.waitForStarted()
proc3.waitForReadyRead(10000)
output3 = proc3.readAll()
print "0"
print output0.size()
print repr(output0.data())
print "1"
print output1.size()
print repr(output1.data())
print "2"
print output2.size()
print repr(output2.data())
print "3"
print output3.size()
print repr(output3.data())
proc0.close()
proc1.close()
proc2.close()
proc3.close()
Is the last test (proc3) supposed to behave like I described? Is there a workaround or a fix that would let me read the data form stdout in my python server…? What is it?
It’s a comment but…
I found the solution, python’s print doesn’t flush stdout and waits for a certain amount of data before actually pushing the data to the stdout. sys.stdout.flush() fixed it.
Hope it helps.