Integrating Two Event Handling Programs In Python
I have two programs in Python. Let's call them Prog1.py and Prog2.py . Prog1 is helping me get live data from an external device. As of now, as and when it gets the data it prints
Solution 1:
You a few options, probably any of which would work:
- Join the programs into one, with a worker thread that monitors for data and sends this back to the main thread for plotting. (see: https://groups.google.com/forum/#!msg/pyqtgraph/haiJsGhxTaQ/RkOov_UZEcYJ)
Join the programs into a single-threaded program, with a timer that checks for new data, and replots whenever data has arrived:
plt = pg.plot() def update(): data = getNewData() ifdatais not None: plt.plot(data, clear=True) timer = QTimer() timer.timeout.connect(update) timer.start(10)
Keep the programs separate and use some form of IPC--sockets, pipes, etc. to communicate between them. This would involve serializing the data (probably with pickle, as you suggest).
pyqtgraph.multiprocess
even lets you send Qt signals between processes. This is probably the most difficult option, but here's an easy example:import pyqtgraph as pg import pyqtgraph.multiprocess as mp proc = mp.QtProcess() # start second process for plotting rpg = proc._import('pyqtgraph') plt = rpg.plot() # create a PlotWidget in remote process# Unlike the last example, we can use a wile-loop here because the Qt# event loop is running in another process.whileTrue: data = getNewData() if data isnotNone: plt.plot(data, clear=True, _callSync='off')
Post a Comment for "Integrating Two Event Handling Programs In Python"