Design Question: GUI+Threads.
Syver Enstad
syver at inout.no
Thu Oct 23 07:42:12 EDT 2003
"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?
One way to do it:
Use two Queue.Queue's. Do non blocking get's and put's from the gui on
a timer. Do blocking gets from the queue instance that the GUI calls
put on, do blocking put's on the queue that the GUI calls get from.
I usually wrap the use of Queue behind a method interface, so that the
GUI calls methods on the threaded class to get and put. If you want to
to use a thread pool you can easily make all the threads can share the
queue instances.
More information about the Python-list
mailing list