Inter-Process comunication

  • Thread starter Zunbeltz Izaola
  • Start date
Z

Zunbeltz Izaola

Hi

I'm writting a program to get data from a machine. I'm using wxPython
to build the GUI. I've a mehtod in a class that get the data,
something like this:

data = []
def Measure(self):
do somehting...
while ...
point = getdatapoint()
data.aapend(point)
do something...

I want to plot the data in a "canvas", but i want to replot each time
a point is added to data. I don't watn to insert the code to plotting
inside the Measure (becose this code is GUI dependent). The code for
plotting is in another function DrawPlOt()

I want something like to send a signal each time the data is changed
to execute DrawPlot(). I'm no proffesional programmer and i don't know
wich technique is the best, signals, theread, anothero one ...
Any sugestions?

TIA

Zunbeltz Izaola
 
I

Irmen de Jong

Zunbeltz said:
I want something like to send a signal each time the data is changed
to execute DrawPlot(). I'm no proffesional programmer and i don't know
wich technique is the best, signals, theread, anothero one ...
Any sugestions?

Have a look at Pyro, http://pyro.sourceforge.net
You could stick your DrawPlot() method in a Pyro object
and call it -remotely- from the process/thread that
generated new data to plot.

--Irmen
 
C

Cameron Laird

Have a look at Pyro, http://pyro.sourceforge.net
You could stick your DrawPlot() method in a Pyro object
and call it -remotely- from the process/thread that
generated new data to plot.
.
.
.
Maybe.

There are several things that are definite. Mr. Izaola deserves
applause for his intent to define clean classes that don't mix
GUI handling (for example) with data communication. I suspect
his use of append() will turn out to be a misstep; Measure should
probably just pass data through without even committing itself to
the sequence data structure he outlined. Also, while Python does
indeed support a variety of inter-process communication (IPC)
mechanisms well, it's almost certain he's best off with some form
of sockets, and definitely not signals or thread management.

What socket abstraction will best suit him? I'm not sure; the
contestants, as I see them, are raw sockets, asyncore, Twisted,
and Pyro. I think raw sockets are too low level. asyncore is
my first choice, but Twisted and Pyro have plenty to recommend
them. 'Anyone have the leisure to supply a working example in
any of these?
 
E

email9898989

Zunbeltz Izaola said:
I want to plot the data in a "canvas", but i want to replot each time
a point is added to data. I don't watn to insert the code to plotting
inside the Measure (becose this code is GUI dependent). The code for
plotting is in another function DrawPlOt()

I want something like to send a signal each time the data is changed
to execute DrawPlot(). I'm no proffesional programmer and i don't know
wich technique is the best, signals, theread, anothero one ...
Any sugestions?

First do you want your data collecting class running as a separate
thread in your wxPython app (simplest way), or as a completely
separate process/application that communicates remotely with your
wxPython app?
To do it using threads, see:
http://wiki.wxpython.org/index.cgi/LongRunningTasks
If it is running as a separate application, then you would need to use
something like sockets/Pyro/Twisted to communicate with your wxPython
app.

Second, if you are just plotting the data, see something like wxPyPlot
or SciPy's wxPython plotting options.
http://scipy.com/
http://www.cyberus.ca/~g_will/wxPython/wxpyplot.html

Next, see the Observer-Observable and Model-View-Controller patterns.
Bruce Eckel has an example of observer and observable in Python:
http://jamesthornton.com/eckel/TIPython/code/util/

Make your data collecting class (the Model) a subclass of Observable.
When it gets new data, it calls its own "notifyObservers" method, and
optionally passes the data value (with or without a time stamp too) as
an argument.

Your wxPython canvas (the View) subclasses Observer, and implements a
"notify" method to receive the new data and draw it. But don't redraw
it immediately if the Model is running in a separate thread, use
something like wxCallAfter(self.RedrawPlot) so that all drawing
happens in the main wxPython application thread (or if you are using
SciPy, see its gui_thread module).

One other problem - if your model is continuously collecting a lot of
data very fast, then your wxPython app will get bogged down if you
redraw every time new data is received. What I do is have the
"notify" method just append the time stamped data to an array (see the
Numeric module). Then I use a wxTimer to draw the new data at regular
intervals.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top