Discussion:
[pyqtgraph] Plotting real time data causes graph to freeze
Keiji
2018-08-26 05:09:16 UTC
Permalink
Hi there. I know this question has been asked many times and a possible
solution is using a timer (QTimer), but in my case it doesn't work. What
I'm doing wrong?

I've also tried to increase the timer step (self.timer.start(200)) and move
the processing part of the code to a new "worker" thread, communicating by
signals with the UI thread.
Here's a simple version of my code:

from PyQt4 import QtGui, QtCore
import multiprocessing, Queue, time, pyqtgraph, sys

#Main window
import Plotter

def Input(queue):
t = time.clock()
queue.put(t)

def Output(queue, v):
v = queue.get()

# -----------------------------------------------------------------
class UI_Thread(QtGui.QMainWindow, Plotter.Ui_MainWindow):
Start_Worker = QtCore.pyqtSignal()

def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.QOn.clicked.connect(self.Calc)
self.q = Queue.Queue(0) #FIFO Constructor
self.v = 0
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.Update)

def Update(self):

p1 = multiprocessing.Process(target=Input, args=(self.q,))
p1.start()
p1.join()

p2 = multiprocessing.Process(target=Output, args=(self.q, self.v))
p2.start()
p2.join()

self.Texto.setText(str(self.v))

def Calc(self):
self.timer.start(200)


# -----------------------------------------------------------------
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
PID = UI_Thread()
PID.show()
app.exec_()
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/f53ac7af-1be3-446a-96c0-de3e8336bc72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Patrick
2018-08-27 02:42:58 UTC
Permalink
Hi,

I've used separate threads to acquire data and then notify the Qt UI thread
using the signals. Demo code for that method here:
https://groups.google.com/d/msg/pyqtgraph/ajykxBvysEc/e1V8lvZSCgAJ

Someone else was trying to use a multiprocessing approach and I gave a
working example of that here:
https://groups.google.com/d/msg/pyqtgraph/VFLVHlNRLHg/gxzDNC_6AgAJ

The issue is you want to start the processes from outside of the Qt event
loop -- the process .join() commands will block until the new process ends,
and so will block the Qt event loop. See example above, where the Qt event
loop (app) is started from inside the receiver process, and the sender and
receiver processes are started in "main" code block.

Patrick
Post by Keiji
Hi there. I know this question has been asked many times and a possible
solution is using a timer (QTimer), but in my case it doesn't work. What
I'm doing wrong?
I've also tried to increase the timer step (self.timer.start(200)) and
move the processing part of the code to a new "worker" thread,
communicating by signals with the UI thread.
from PyQt4 import QtGui, QtCore
import multiprocessing, Queue, time, pyqtgraph, sys
#Main window
import Plotter
t = time.clock()
queue.put(t)
v = queue.get()
# -----------------------------------------------------------------
Start_Worker = QtCore.pyqtSignal()
super(self.__class__, self).__init__()
self.setupUi(self)
self.QOn.clicked.connect(self.Calc)
self.q = Queue.Queue(0) #FIFO Constructor
self.v = 0
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.Update)
p1 = multiprocessing.Process(target=Input, args=(self.q,))
p1.start()
p1.join()
p2 = multiprocessing.Process(target=Output, args=(self.q, self.v))
p2.start()
p2.join()
self.Texto.setText(str(self.v))
self.timer.start(200)
# -----------------------------------------------------------------
app = QtGui.QApplication(sys.argv)
PID = UI_Thread()
PID.show()
app.exec_()
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/f21b512a-8493-465a-8b80-d5e6f6c78cdc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...