[Python-checkins] python/dist/src/Lib threading.py,1.41,1.42
bcannon at users.sourceforge.net
bcannon at users.sourceforge.net
Fri Jul 2 23:52:37 EDT 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30134/Lib
Modified Files:
threading.py
Log Message:
threading.Thread objects will now print a traceback for an exception raised
during interpreter shutdown instead of masking it with another traceback about
accessing a NoneType when trying to print the exception out in the first place.
Closes bug #754449 (using patch #954922).
Index: threading.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/threading.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** threading.py 8 Mar 2004 22:18:57 -0000 1.41
--- threading.py 3 Jul 2004 03:52:35 -0000 1.42
***************
*** 368,371 ****
--- 368,376 ----
__initialized = False
+ # Need to store a reference to sys.exc_info for printing
+ # out exceptions when a thread tries to use a global var. during interp.
+ # shutdown and thus raises an exception about trying to perform some
+ # operation on/with a NoneType
+ __exc_info = _sys.exc_info
def __init__(self, group=None, target=None, name=None,
***************
*** 382,385 ****
--- 387,393 ----
self.__block = Condition(Lock())
self.__initialized = True
+ # sys.stderr is not stored in the class like
+ # sys.exc_info since it can be changed between instances
+ self.__stderr = _sys.stderr
def _set_daemon(self):
***************
*** 439,444 ****
if __debug__:
self._note("%s.__bootstrap(): unhandled exception", self)
! _sys.stderr.write("Exception in thread %s:\n%s\n" %
! (self.getName(), _format_exc()))
else:
if __debug__:
--- 447,480 ----
if __debug__:
self._note("%s.__bootstrap(): unhandled exception", self)
! # If sys.stderr is no more (most likely from interpreter
! # shutdown) use self.__stderr. Otherwise still use sys (as in
! # _sys) in case sys.stderr was redefined since the creation of
! # self.
! if _sys:
! _sys.stderr.write("Exception in thread %s:\n%s\n" %
! (self.getName(), _format_exc()))
! else:
! # Do the best job possible w/o a huge amt. of code to
! # approximate a traceback (code ideas from
! # Lib/traceback.py)
! exc_type, exc_value, exc_tb = self.__exc_info()
! try:
! print>>self.__stderr, (
! "Exception in thread " + self.getName() +
! " (most likely raised during interpreter shutdown):")
! print>>self.__stderr, (
! "Traceback (most recent call last):")
! while exc_tb:
! print>>self.__stderr, (
! ' File "%s", line %s, in %s' %
! (exc_tb.tb_frame.f_code.co_filename,
! exc_tb.tb_lineno,
! exc_tb.tb_frame.f_code.co_name))
! exc_tb = exc_tb.tb_next
! print>>self.__stderr, ("%s: %s" % (exc_type, exc_value))
! # Make sure that exc_tb gets deleted since it is a memory
! # hog; deleting everything else is just for thoroughness
! finally:
! del exc_type, exc_value, exc_tb
else:
if __debug__:
More information about the Python-checkins
mailing list