You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Programs\Python37\lib\tkinter\__init__.py", line 1699, in __call__returnself.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 baddefbad(): print(a, 'bad')
NameError: name 'a' is not defined
good
>>>
====================================
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.
-------------
>>> Exceptionin Tkinter callback
Traceback (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 Empty
queue.Empty
During 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.
Experiments 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 None
However, 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.
changed the title [-]IDLE: run's tk update adds extra traceback on callback error[/-][+]IDLE: run's tk update adds context traceback on callback error[/+]on Dec 4, 2017
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.
New changeset 9da33c8 by Terry Jan Reedy (Miss Islington (bot)) in branch '3.6': bpo-32207: Improve tk event exception tracebacks in IDLE. (GH-4703) (bpo-4705) 9da33c8
Activity
terryjreedy commentedon Dec 4, 2017
# Correctly gives this traceback and output:
====================================
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.
-------------
The relevant code in run.py was written before callback chaining.
Experiments 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 None
However, 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.
[-]IDLE: run's tk update adds extra traceback on callback error[/-][+]IDLE: run's tk update adds context traceback on callback error[/+]serhiy-storchaka commentedon Dec 4, 2017
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
terryjreedy commentedon Dec 4, 2017
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.
terryjreedy commentedon Dec 4, 2017
New changeset 1e2fcac by Terry Jan Reedy in branch 'master':
bpo-32207: Improve tk event exception tracebacks in IDLE. (bpo-4703)
1e2fcac
terryjreedy commentedon Dec 4, 2017
New changeset 9da33c8 by Terry Jan Reedy (Miss Islington (bot)) in branch '3.6':
bpo-32207: Improve tk event exception tracebacks in IDLE. (GH-4703) (bpo-4705)
9da33c8