Movatterモバイル変換


[0]ホーム

URL:


[Python-bugs-list] [ python-Bugs-231207 ] Fatal Python Error during program shutdown

noreply@sourceforge.netnoreply@sourceforge.net
Sat, 02 Nov 2002 22:52:24 -0800


Bugs item #231207, was opened at 2001-02-06 02:50You can respond by visiting:https://sourceforge.net/tracker/?func=detail&atid=105470&aid=231207&group_id=5470Category: TkinterGroup: NoneStatus: OpenResolution: NonePriority: 5Submitted By: Doug Henderson (djhender)Assigned to: Nobody/Anonymous (nobody)Summary: Fatal Python Error during program shutdownInitial Comment:The windows builds of versions 2.0 and 2.1a2 contain an intermittent bug which often appears when a script using Tkinter stops by calling self.tk.quit() and sometimes (less often) appears following a <Destroy> event or call to a ?.destory() function.Under Windows 98SE, this results in a GPF.Under Windows 2000, a message to the console window shows "Fatal Python Error", "PyEval_RestoreThread NULL tstate".The following script demonstrates the problem:---------------------# BugDemo.pyfrom Tkinter import *class BugDemo(Frame):    def __init__(self, parent):        Frame.__init__(self, parent)        Button(self, text='Hi', command=self.hi).pack()        Button(self, text='Quit', command=self.tk.quit).pack()    def hi(self):        print "hi"bd = BugDemo(Tk())bd.pack()bd.mainloop()----------------------Execute in console window: "c:> python BugDemo.py"Test this by 1) clicking Quit button 2) clicking Hi button, then Quit button.Test 1: The script runs successfully most of the time. I found I had to minimize and restore its window to make it fail regularly.Test 2: I need to click Hi button before clicking the Quit button. Then it failed about half the time.The problem appears to occur after the script has completed, during some kind of cleanup perhaps. The more useful error message on the Win2k machine may help to locate the problem.Problem also manifests using the PythonWare 2.0 release on Win98.----------------------------------------------------------------------Comment By: Internet Discovery (idiscovery)Date: 2002-11-03 06:52Message:Logged In: YES user_id=33229I know I'm a Python newbie but I know Tcl well and I think I know at least part of what's going on. Looking specifically at nobody's2002-04-22 14:21 code, I see that this uses mainloop and quitin a way that many Python books and examples do, as if quit()will "Quit the Tcl interpreter. All widgets will be destroyed."But if you look at MainLoop and Quit in _tkinter.c you see thatQuit just sets a variable that causes MainLoop to end - itdoesn't destroy anything nor quit the interpreter. IMHO all Tkinter programs need a root.destroy() after root.mainloop()If you change nobody's program to add a root.destroy() it runs fine underPythonWin.The "bug" is in the documentation of quit() in Tkinter.py    def quit(self):        """Quit the Tcl interpreter. All widgets will be destroyed."""        self.tk.quit()The comment should read         """Quit the main event loop. It is up to you to call root.destroy() after."""If I'm right the documentation for Tkinter in the library reference should bechanged too; there should be a root.destroy() at the end ofhttp://www.python.org/doc/2.2.1/lib/node503.htmlIf I'm right then I'll stick my neck out a little further: Tkinter's mainloop and quitshould be dropped from _tkinter.c and replaced with the following idiomand usage:In Tkinter.py declare a class variable in Misc: _exit = -1 and change in MiscTCL_ALL_EVENTS= 0    def quit(self):        """Quit the Tcl interpreter. All widgets will be destroyed."""        self._exit = 0    def mainloop(self):        """Loop until we call quit()"""        while self._exit < 0:            try:                self.root.tk.dooneevent(TCL_ALL_EVENTS)            except SystemExit:                #print 'Exit'                self.exit = 1                break            except                # do something intelligent with errors or interruptsI believe this is more transparent and more open to creativity.I have experimented (all my code is like this now) and feel that there is no performance penalty to looping in Python.In addition it avoids the 20msec sleep in _tkinter.mainloop()that is an abomination. It would also allow people to think more clearly about what happenswhen you have 2 Tk() instances, in which case you have 2 Tclinterpeters. It may make you move _exit to be an instancevariable of the Tk class. In any event you'll be able to see what'sgoing on.----------------------------------------------------------------------Comment By: Nobody/Anonymous (nobody)Date: 2002-04-22 14:21Message:Logged In: NO I confirm the behaviour for:WinNT 4.0 SP5tested with Python 2.2Beta1 (ActiveState)tested with Python 2.2.1.222 (ActiveState)PythonWinIDE will hang when the following program is "quit"ted.But will "quit" normally when run standalone (not within PythonWinIDE):# # from Tkinter import *from tkMessageBox import *class App:    def __init__(self, winRoot):        frame = Frame(winRoot)        frame.pack()        self.btnQuit = Button(frame, text="QUIT", bg="blue", foreground="light blue", command=frame.quit)        self.btnQuit.pack(side=LEFT)        self.btnHiThere = Button(frame, text="Hi there!",command=self.sayHiThere)        self.btnHiThere.pack(side=LEFT)    def sayHiThere(self):        showinfo("Greeting", "Hi There")                if __name__ == "__main__":    root = Tk()    test = App(root)    root.mainloop()----------------------------------------------------------------------Comment By: Jeremy Hylton (jhylton)Date: 2002-03-01 22:49Message:Logged In: YES user_id=31392Unassign as it appears that effbot isn't going to look at it.----------------------------------------------------------------------Comment By: Nobody/Anonymous (nobody)Date: 2001-07-18 11:13Message:Logged In: NO i won't to be a hacker----------------------------------------------------------------------Comment By: Nobody/Anonymous (nobody)Date: 2001-05-29 07:30Message:Logged In: NO Note:I am running Windows98ActivePython 2.1Even with console apps in python this same error appearsI tried using another Distribution of Python for win32, PythonWare20So this leads me to believe that some lib is missing on win98. Because at work I use Win95, and Installed ActivePython 2.1, and it works fine and dandy----------------------------------------------------------------------Comment By: Joel Gould (joelgould)Date: 2001-03-24 16:52Message:Logged In: YES user_id=20954I also see a GPF on shutdown under Windows 98 using Tkinter.  I tested this using the PythonWare 2.0 release as well.I have attached a very simple Tkinter program.  When I run this on my Windows 98 SE machine, a crash occurs when the program exits.  Without the MainDialog class it works OK.  Without the Pmw initialization call it works OK.  But as written it will crash around 75% of the time.(1) run the program(2) press the Test Button(3) click Cancel in the file open dialog (you do not need to select a file)(4) click the close button in the upper right corner-->  Boom--------------------import Tkinterimport tkFileDialogimport Pmwdef action():    tkFileDialog.askopenfilename(filetypes=[('All','*')])class MainDialog:    def __init__(self,parent):        Tkinter.Button(parent,text='Test Button',command=action).pack()root = Pmw.initialise()dialog = MainDialog(root)root.mainloop()----------------------------------------------------------------------Comment By: Tim Peters (tim_one)Date: 2001-02-09 23:34Message:Assigned to /F, under the theory he can confirm that "this kind of thing" is still a general problem with Tk we can't do anything about.----------------------------------------------------------------------Comment By: Doug Henderson (djhender)Date: 2001-02-06 05:30Message:See also #116289 (and my comment to it) which describes what often happened to my 'real' programs which lead to developing the above BugDemo script. My 'real' programs were developed over the last two years or so, and worked in Jan 2000 with 1.5.2. I upgraded the Python version recently, and then started working on these programs again. It was "WTF is wrong with my code", until I found the same problem showing up in the small test cases.----------------------------------------------------------------------You can respond by visiting:https://sourceforge.net/tracker/?func=detail&atid=105470&aid=231207&group_id=5470


[8]ページ先頭

©2009-2025 Movatter.jp