Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue32207

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:IDLE: run's tk update adds context traceback on callback error
Type:behaviorStage:resolved
Components:IDLEVersions:Python 3.7, Python 3.6
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: terry.reedyNosy List: serhiy.storchaka, terry.reedy
Priority:normalKeywords:patch

Created on2017-12-04 01:47 byterry.reedy, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 4703mergedterry.reedy,2017-12-04 20:07
PR 4705mergedpython-dev,2017-12-04 21:17
Messages (5)
msg307534 -(view)Author: Terry J. Reedy (terry.reedy)*(Python committer)Date: 2017-12-04 01:47
import tkinter as tkroot = tk.Tk()def bad(): print(a, 'bad')def good(): print('good')root.after(1000, bad)root.after(1500, good)root.mainloop()# Correctly gives this traceback and output:Exception in Tkinter callbackTraceback (most recent call last):  File "C:\Programs\Python37\lib\tkinter\__init__.py", line 1699, in __call__    return self.func(*args)  File "C:\Programs\Python37\lib\tkinter\__init__.py", line 745, in callit    func(*args)  File "F:\Python\a\tem2.py", line 13, in bad    def bad(): print(a, 'bad')NameError: name 'a' is not definedgood>>> ====================================Remove or comment-out the blocking 'root.mainloop()' call and run the result from an IDLE editor.  The callbacks are still called because after user code is run, run.py calls tcl.update in a loop nominally 20 x per second.  This allows developers to interact with a 'live' gui by entering statements in the shell at '>>>' prompts.  The result is this.------------->>> Exception in Tkinter callbackTraceback (most recent call last):  File "C:\Programs\Python37\lib\idlelib\run.py", line 137, in main    seq, request = rpc.request_queue.get(block=True, timeout=0.05)  File "C:\Programs\Python37\lib\queue.py", line 169, in get    raise Emptyqueue.EmptyDuring handling of the above exception, another exception occurred:Traceback (most recent call last):<The NameError traceback and message, as before.>--------------The relevant code in run.py was written before callback chaining.            try:                seq, request = rpc.request_queue.get(block=True, timeout=0.05)            except queue.Empty:                handle_tk_events()                continueExperiments with normal exceptions in a shell suggest that wrapping handle_tk_events in try:except and re-raising any exception 'from None' should work.                try:                    handle_tk_events()                except BaseException as e:                    raise e from NoneHowever, it appears that callback errors resulting from handle_tk_events() are not being caught here.  (print('message') and 1/0 before 'raise' have no visible effect.)  I will investigate more later.
msg307541 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-12-04 06:17
try:                seq, request = rpc.request_queue.get(block=True, timeout=0.05)            except queue.Empty:                request = None            if request is None:                handle_tk_events()                continue
msg307594 -(view)Author: Terry J. Reedy (terry.reedy)*(Python committer)Date: 2017-12-04 20:12
Thanks.  I am still puzzled why the nested within nested try-except did not work as I expected, but I care more about fixing this. The result based on your suggestion is better (to read, I think) than extra nesting that did work.
msg307597 -(view)Author: Terry J. Reedy (terry.reedy)*(Python committer)Date: 2017-12-04 21:16
New changeset1e2fcac4972530aa2c963d7e4011021df5ba866e by Terry Jan Reedy in branch 'master':bpo-32207: Improve tk event exception tracebacks in IDLE. (#4703)https://github.com/python/cpython/commit/1e2fcac4972530aa2c963d7e4011021df5ba866e
msg307599 -(view)Author: Terry J. Reedy (terry.reedy)*(Python committer)Date: 2017-12-04 22:02
New changeset9da33c82124f27eb58ba4cf145675fe7a1035744 by Terry Jan Reedy (Miss Islington (bot)) in branch '3.6':bpo-32207: Improve tk event exception tracebacks in IDLE. (GH-4703) (#4705)https://github.com/python/cpython/commit/9da33c82124f27eb58ba4cf145675fe7a1035744
History
DateUserActionArgs
2022-04-11 14:58:55adminsetgithub: 76388
2017-12-04 22:04:00terry.reedysetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-12-04 22:02:34terry.reedysetmessages: +msg307599
2017-12-04 21:17:26python-devsetpull_requests: +pull_request4617
2017-12-04 21:16:20terry.reedysetmessages: +msg307597
2017-12-04 20:34:02terry.reedysetstage: needs patch -> patch review
2017-12-04 20:12:32terry.reedysetmessages: +msg307594
stage: patch review -> needs patch
2017-12-04 20:07:31terry.reedysetkeywords: +patch
stage: needs patch -> patch review
pull_requests: +pull_request4615
2017-12-04 06:17:05serhiy.storchakasetnosy: +serhiy.storchaka
messages: +msg307541
2017-12-04 01:47:39terry.reedysettitle: IDLE: run's tk update adds extra traceback on callback error -> IDLE: run's tk update adds context traceback on callback error
2017-12-04 01:47:09terry.reedycreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp