1
votes

I'm using wxPython as the front end for a data acquistion system, the backend using PyDAQmx to interface to a national instruments card.

When the loop is called to collect the data, obviously the gui blocks, so I put the acquisition module in a separate thread using threading.Thread. However, the data comes in so fast that we actually need more than one core, which I believe threading.Thread can't do.

I next tried spawning a separate process using multiprocessing.Process & Queue to report the data back, quite simply as

captureProcess = Process(target=acquire, args=(self.settings, self.queue,))
captureProcess.start()

The data is sent down the queue with

queue.put( (i, j, c, aiData.value) )

and picked up again with

(scan, interval, count, ai) = queue.get()

Now the bizarre bit is that the gui doesn't block in the sense I can update some pyplot graphs on the main wx.Frame, but any interaction with it (clicking a menu, etc), immediately causes the program to become unresponsive and crash. Does anyone know why this might be, or any workaround?

Many thanks for your help. I'm using anaconda on Windows 7.

1
Try starting the process early - before setting up wxpython. The less state pushed to the data collection process the better. - tdelaney
Have you tried incorporating wx.Yield() within the loops? This will allow the GUI to update and then return to the loop. And you may not need to thread it out using this, but then again I haven't used anaconda, so I'm not sure what it might do. - Ryan G
Thanks for your help. I can't start the process early as it needs to be started when the user begins data capture. As the loops are in the separate process, for wx.Yield() I'd need to pass a copy of the current app, but that can't be pickled so it appears it won't work. Any more suggestions appreciated. - kezz_smc

1 Answers

1
votes

Make absolutely sure that there is no GUI interaction in the thread - nor direct thread interaction in the GUI. The GUI can call setter functions in the thread that change member values that the thread checks periodically and the thread can cause GUI results by posting events, with additional data.

One of the lovely features of wxPython is that custom events can carry any type of data for you.

As one of the features of Queue is that if the slots are full it will hang and while your GUI is acting on things like menu clicks you will not be servicing your queue I suspect you are overflowing - you should be catching the Full exception and doing something like discarding the data and setting a data lost flag.