seg fault

Eric Brunel eric_brunel at
Thu Nov 4 16:02:47 CET 2004

Ajay wrote:
> hi!
> 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?
> the code is
[snip code]

Can you reproduce the problem with a simpler script? For example, does the 
following script work for you:

import time, threading
from Tkinter import *

class MyApp:

   def __init__(self):
     self.root = Tk() = 0
     self.lbl = Label(self.root, text='idle', width=6)
     self.root.bind('<<go>>', self.toggleLabel)
     th = threading.Thread(target=self.runThread)

   def run(self):

   def toggleLabel(self, ping):
       self.lbl['text'] = 'ping'
       self.lbl['text'] = 'pong' = not

   def runThread(self):
     while 1:
       self.root.event_generate('<<go>>', when='tail')

app = MyApp()

I used this trick many times to make secondary threads communicate with a 
Tkinter GUI, and never encountered a seg fault.

Since you apparently use custom modules, I'd say that the problem is more likely 
to come from these modules, and not from Python or Tkinter. Is the elvin module 
written in Python or in C or C++? If it is written in C or C++, since it uses a 
Python callback (sub.add_listener(self.answerMessage)), make sure it correctly 
handles the global interpreter lock. If it doesn't, it may be the cause of your 
seg fault.

- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools -

More information about the Python-list mailing list