views:

49

answers:

1

Hi

I have a wxpython app designed using XRC which has a multiline textctrl inside nested boxlayouts.

I'm adding some text(retrieved from the web) to the text control using SetValue(), inside the longtask method from a separate thread using the following code

thread.start_new_thread(self.longtask, ())

The app runs fine the first couple of tries(text gets added correctly) but after around 3 or 4 times it exits with a segmentation fault and following warning.

(python:3341): Gtk-WARNING **: unable to find signal handler for object(GtkEntry:0x9ed89e0) with func(0x837600) and data(0x9e19c08)

Does anyone know why this is happening and how I can fix it? I'm running Python2.6 on Ubuntu 10.2.

Thanks in advance.

+2  A: 

Directly calling methods of GUI elements from a different thread is dangerous. Without getting too much into your code, I'd recommend you to consider a robust multi-threaded design. For example, you can use Queue objects to pass data between threads. Alternatively, use wx's events.

Here's a nice article on this issue. And a related SO discussion. Google for more ('wxpython thread')

Eli Bendersky
Hi eli, thanks for your answer. The problem got fixed after I put all UI handling code in a separate method and calling it using wx.CallAfter(). I first tried using queues but couldn't get it to work. Would there be any advantages using queues for communication over wx.CallAfter() ?
jimbo
@jimbo: IIRC the article I pointed to discusses and compares these options
Eli Bendersky
yes, but the said discusses don't tell my WHY I would choose one option over another.Anyway, you're right, it doesn't probably matter for my current app.
jimbo