Fatal Python error: PyEval_RestoreThread: NULL tstate

我与影子孤独终老i 提交于 2019-12-11 08:46:12

问题


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..


回答1:


What version of gtk are you using? This link seems to indicate it's a threading bug that was fixed in 2.0.1.



来源:https://stackoverflow.com/questions/7434408/fatal-python-error-pyeval-restorethread-null-tstate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!