seg fault

exarkun at exarkun at
Thu Nov 4 15:43:48 CET 2004

On Fri,  5 Nov 2004 01:06:07 +1100, Ajay <abra9823 at> wrote:
> i have some code with a gui that does some processing in another thread,
> say t2.
> when t2 needs to display something on the gui, it generates an event (which
> i have binded earlier). the code runs fine on windows but segfaults on
> linux.
> the point where it segfaults is when it generates the event.
> any ideas why?

  You're calling Tk functions in a non-main thread.  This isn't allowed.  I see that you are creating a Queue, which is a good first step towards fixing this problem, but then it isn't used anywhere.

  Instead of the last line of:

> 	def answerMessage(self, sub, msg, insec, rock):
> 		print msg
> 		self.reply = msg.get("SMSMessage")
> 		dest = msg.get("SMSDestination")
> 		if dest == self.phnumber:
> 			self.frame.event_generate('<<reply>>', when='tail')

  You may want something like:

    func = self.frame.event_generate
    args = ('<<reply>>',)
    kwargs = {'when': 'tail'}
    self.q.put((func, args, kwargs))

  This doesn't call the Tk function, but instead adds enough information to call it to the Queue instance.  The main thread should then poll the Queue instance and call whatever it finds there:

    def checkQueue(self):
        # Reschedule this call

        while not self.q.empty():
            func, args, kwargs = self.q.get()
            func(*args, **kwargs)

  Hope this helps,


More information about the Python-list mailing list