MVC design with threading and Queue?

Hi all,

I am developing my first large and complex python/wxpython app and I need
help on how to implement an MVC design using threads which will
communicate via a Queue.

Here is an overview of what the application is trying to do:

[MODEL]-[WorkerThread1] : open serial port 1 and continuously wait for data
[MODEL]-[WorkerThread2] : open serial port 2 and continuously wait for data
[MODEL]-[WorkerThread3] : query a PostgreSQL DB using data from serial
ports and return data for display to the VIEW.
[VIEW]-[main thread] : wxpython app
[CONTROLLER] : starts VIEW and MODEL threads and passes data between MODEL
and VIEW.

User interaction with the system is mainly via serial port events. GUI is
used mainly for display. So the CONTROLLER should start the background
MODEL threads.

My question first of all is if this is do-able.
Secondly, I'm not sure how to put/get data to the queues WITHOUT polling.
One way I've seen around is via wx.WakeUpIdle() and wx.EVT_IDLE, but this
way it seems to me I cannot have separate CONTROLLER and VIEW.

Can anyone post an example of how I can achieve this? Perhaps with how to
shutdown threads properly when the GUI is closed by the user.

Thanks
Menelaos Maglis

P.S. I've searched and read many manuals/wikis/mailing-lists with no clear
example on how to combine both MVC and threading.

mmaglis@visionplus.gr wrote:

My question first of all is if this is do-able.

Yes. It is possible. Though you want to make sure that the thread that
is running your GUI is also the thread that created your wx.App instance,
otherwise wxPython may complain (and/or not work).

Secondly, I'm not sure how to put/get data to the queues WITHOUT polling.
One way I've seen around is via wx.WakeUpIdle() and wx.EVT_IDLE, but this
way it seems to me I cannot have separate CONTROLLER and VIEW.

This recipe uses events to give the main thread information:
http://wiki.wxpython.org/index.cgi/AsynchronousSockets

You could also use wx.CallAfter(fcn, *args, **kwargs) to get a function
call to run in the GUI thread (it uses events under the covers).

- Josiah