Reputation: 1492
Does somebody knows what this error means?
Fatal Python error: PyEval_RestoreThread: NULL tstate
In my application when I destroy the main window this error is printed. I am using multiples threads to run differents jobs in the same time.
I really dont have any ideia what is this..
If someone ever lived the same problem please help me..
Below is a code to show how to reproduce this error. (I tried to make smallest code that I could)
#!/usr/bin/env python
import gtk
import threading
import sys
class Test(threading.Thread):
"""A subclass of threading.Thread, with a kill() method."""
def __init__(self, *args, **keywords):
threading.Thread.__init__(self, *args, **keywords)
gtk.gdk.threads_init()
self.killed = False
def start(self):
"""Start the thread."""
self.__run_backup = self.run
self.run = self.__run # Force the Thread to install our trace.
threading.Thread.start(self)
def __run(self):
"""Hacked run function, which installs the trace."""
sys.settrace(self.globaltrace)
self.__run_backup()
self.run = self.__run_backup
def globaltrace(self, frame, why, arg):
if why == 'call':
return self.localtrace
else:
return None
def localtrace(self, frame, why, arg):
if self.killed:
if why == 'line':
raise SystemExit()
return self.localtrace
def kill(self):
self.killed = True
class Window(gtk.Window):
"""Main window"""
def __init__(self):
"""Create a main window and all your children"""
super(Window, self).__init__()
self.connect('destroy', gtk.main_quit)
button = gtk.Button("Click and after, close window")
button.connect("clicked", self.on_item_run)
self.add(button)
self.show_all()
def on_item_run(self, widget):
t = Test()
t.start()
if __name__ == "__main__":
window = Window()
gtk.gdk.threads_enter()
gtk.main()
gtk.gdk.threads_leave()
Thanks a lot..
Upvotes: 3
Views: 9072