seg fault

Eric Brunel eric_brunel at despammed.com
Thu Nov 4 10:02:47 EST 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()
     self.ping = 0
     self.lbl = Label(self.root, text='idle', width=6)
     self.lbl.pack()
     self.root.bind('<<go>>', self.toggleLabel)
     th = threading.Thread(target=self.runThread)
     th.setDaemon(1)
     th.start()

   def run(self):
     self.root.mainloop()

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

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

app = MyApp()
app.run()
---------------------------------------------------------------------

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.

HTH
-- 
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com



More information about the Python-list mailing list