pythonsocketsenthoughtchacotraitsui

What is a viable approach to receiving asynchronous sources of data for plotting with Chaco?


I'm exploring the Traits/TraitsUI/Chaco packages from Enthought as I'd like to make use of the powerful dynamic plotting facilities. I have data coming from an external source that I wish to use to update a set of Chaco plots. I've studied the spectrum.py and data_stream.py examples, but they regularly pull data from a stream/file/source on a recurring Timer event rather than receiving asynchronous input events.

It's not clear to me how one would remove the Timer and instead trigger the Array updates asynchronously. It might be possible to poll with the Timer, but I want to expand to incorporate several different external sources and I need a 'server' process of some sort to manage this - it can't really be blocked by the GUI main loop. As of right now, I want to incorporate a TCP server that accepts unpredictably occurring incoming client connections, each providing new data to plot.

Is it possible to set up a second thread that can handle all socket communications and use this to call .set_data() to trigger the plot redrawing? Or will this interfere with the GUI main loop and/or cause race conditions within Traits/Chaco?

Or is there an alternative way to think about this problem that makes more sense in the Traits paradigm?


Solution

  • 'set_data' does trigger the redraw, so no timer is needed. But note that the redraw happens in the main gui thread.