Design Question: GUI+Threads.

Brian Kelley bkelley at wi.mit.edu
Thu Oct 23 11:06:52 EDT 2003


Syver Enstad wrote:

> "Frithiof Andreas Jensen" <frithiof.jensen at removethis.ted.ericsson.dk> writes:
> 
> 
>>Hi All,
>>
>>I am tinkering with a stock-market analysis program that needs to have (at
>>least one) a worker thread for processing real-time data and a GUI where one
>>can control/monitor the function of the worker, set parameters and so forth.
>>
>>Is there an elegant and generic way to implement the typical "Model, View,
>>Controller" pattern so that the "Model+Controller" execute in the context of
>>the worker thread and the "View" will execute in the GUI thread - and
>>communication between the two is thread-safe and simple?

You might make your life easier by having the controller and the view be 
on the main thread and dispatch a new model to the work thread.

Contoller -> starts or attaches to view
           -> starts a new model

model -> signals events to controller which updates view
controller -> sets model states when necessary.

Usually you can wrap model events into gui events and let the gui's 
mainloop sort them out and dispatch them to the controllers callbacks.

In python it is thread safe to set variables across the thread boundary, 
the model will have to check for these variables changing though.  The 
standard variable is set by thread.kill() see the threading module for 
more details.

What gui framework are you using?

Brian Kelley





More information about the Python-list mailing list