Terry J. Reedy added the comment:
In a pythonw process, stdout and stderr are initially None unless and until
changed. (This is something we need to do for the Idle process itself.)
Writing to None generates an AttributeError. Uncaught exceptions stop the
Python process.
The patch works, for this particular case, in the sense of preventing process
termination. Print suppresses the exception-reporting exception (after trying
sys.stdout as a backup). It still fails at delivering the original exception
message and traceback. 'Click', and nothing happens.
A developer need to see the specific message and users should at least know
that something is wrong. The following alternate delivers the message in
addition to suppressing the AttributeError. It is a a copy and paste
replacement for the existing "def report_callback_exception" statement. (It was
easier for me to experiment with my installed, non-repository Pythons).
class _Errbox:
def __init__(self):
self.txt=[]
from tkinter.messagebox import showerror
self.showerror = showerror
def write(self, txt):
self.txt.append(txt)
def show(self):
self.showerror(
title="Exception in Tkinter callback",
message=''.join(self.txt))
self.txt = []
def report_callback_exception(self, exc, val, tb):
"""Internal function. It reports exception on sys.stderr."""
import traceback
try:
sys.stderr.write("Exception in Tkinter callback\n")
efile = sys.stderr
except AttributeError:
efile = self._Errbox()
sys.last_type = exc
sys.last_value = val
sys.last_traceback = tb
traceback.print_exception(exc, val, tb, file=efile)
if isinstance(efile, self._Errbox):
efile.show()
I checked and this is the only direct .write in the file. There is only one
other print (to the default sys.stdout).
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue22384>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com