This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Aivar.Annamaa, serhiy.storchaka, terry.reedy
Date 2014-09-13.21:06:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1410642398.47.0.84930054247.issue22384@psf.upfronthosting.co.za>
In-reply-to
Content
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).
History
Date User Action Args
2014-09-13 21:06:38terry.reedysetrecipients: + terry.reedy, Aivar.Annamaa, serhiy.storchaka
2014-09-13 21:06:38terry.reedysetmessageid: <1410642398.47.0.84930054247.issue22384@psf.upfronthosting.co.za>
2014-09-13 21:06:38terry.reedylinkissue22384 messages
2014-09-13 21:06:37terry.reedycreate