> Thanks Robin,
> I had seen the wiki, and I have your book; and, DocView does not seem
> right for this app.
> I jin'd up a little wx demo app that demonstrates MVC, threads, and
> pubsub with Boa,
>http://rjs.org/test/kwargs_threaded.zip
> but I seem to need a wx.Yield() in the while started by a listener
> method. This seems undesirable in a Model that should not are about a GUI.
Pubsub does not automatically cross thread boundaries when subscribers
subscribe in a different thread than where the message is published.
You'll have to help it to do that. In your example the DataCollector
thread terminates at the end of the run() method, and the calls to the
subscribed methods for the published messages are actually happening in
the context of the GUI thread, which is why you have to call wx.Yield to
prevent it from blocking.
In this case it might be just as well to init the Model in the App
thread, and call the psOnStartData() method in the new thread. The
assumption is that the data method is I/O intensive and would benefit
from threading. I had considered forking a process and using IPC and
shared memory before testing Enthought's MKL enabled distro, but I
think I would prefer threading.
I want to avoid PostEvent() use since that requires a wx app to be
connected.
> The problem is that since pub.sendMessage does not return until the
> listener does ("/it does garantee that upon return from the send
> operation, all listeners have handled the message and returned without
> exception."/), without yield in the while loop the GUI stops responding.
> What is the best way to handle this otherwise? The Controller sending a
> message should not have to wait for a Model's response, but, I want to
> initiate the data collection method/loop in the other thread by sending
> the Model a message.
> One way that works (tested) is to have the Model's subscribe() call a
> simple method which then starts the psOnStartData() method in yet
> another thread, but should that be necessary?
> The example could be informative for coders, but needs some tweaks I'd
> think.
One approach that comes to mind is to have the thread waiting in a loop
(in the run() method) for an item to be added to a Queue. The methods
subscribed to the pubsub topic will expect to be running in the gui
thread and will simply create an object to add to that Queue and then
will return. When the thread is woke up by the item being added to the
Queue then it can fetch the obj, do whatever is needed to process it,
and then fetch or wait for the next item to be added to the Queue object.
I could probably have the run() poll the Queue and sleep()
Another option is I'll allow the Controller to call the Model's API
directly, rather than simply signal. This still does not tie the V-C
to wx so it seems OK. It is also conceptually simpler.
I'm also looking at
http://pydispatcher.sourceforge.net/
although I haven't seen much example code other than
http://wxpython-users.1045709.n5.nabble.com/wxPython-signals-tt2330794.html#a2330806\#none,
and indications are that it will not cross threads either.
More tests to do Monday...
Thanks,
Ray
···
On Jun 18, 12:13 pm, Robin Dunn <ro...@alldunn.com> wrote:
On 6/17/11 3:39 PM, Ray S wrote: