[Python-checkins] python/dist/src/Lib threading.py,1.38,1.38.6.1

bcannon at users.sourceforge.net bcannon at users.sourceforge.net
Sat Jul 3 15:59:00 EDT 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6118/Lib

Modified Files:
      Tag: release23-maint
	threading.py 
Log Message:
threading.Thread used to raise an exception about attempting to execute a
NoneType if an exception in a thread was raised during interpreter shutdown.
This led to a masking of the initial exception (not good).  All fixed (good).

Closes bug #754449 (using both patch #954922 and a backport of rev. 1.41 from
HEAD).


Index: threading.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/threading.py,v
retrieving revision 1.38
retrieving revision 1.38.6.1
diff -C2 -d -r1.38 -r1.38.6.1
*** threading.py	1 Jul 2003 20:01:55 -0000	1.38
--- threading.py	3 Jul 2004 19:58:57 -0000	1.38.6.1
***************
*** 194,198 ****
  
      def wait(self, timeout=None):
-         currentThread() # for side-effect
          assert self._is_owned(), "wait() of un-acquire()d lock"
          waiter = _allocate_lock()
--- 194,197 ----
***************
*** 236,240 ****
  
      def notify(self, n=1):
-         currentThread() # for side-effect
          assert self._is_owned(), "notify() of un-acquire()d lock"
          __waiters = self.__waiters
--- 235,238 ----
***************
*** 370,373 ****
--- 368,376 ----
  
      __initialized = False
+     # Need to store a reference to sys.exc_info for printing
+     # out exceptions when a thread tries to accept a global 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,
***************
*** 384,387 ****
--- 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 during execution
+         self.__stderr = _sys.stderr
  
      def _set_daemon(self):
***************
*** 441,448 ****
                  if __debug__:
                      self._note("%s.__bootstrap(): unhandled exception", self)
!                 s = _StringIO()
!                 _print_exc(file=s)
!                 _sys.stderr.write("Exception in thread %s:\n%s\n" %
!                                  (self.getName(), s.getvalue()))
              else:
                  if __debug__:
--- 447,478 ----
                  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.
!                 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
!                     # approx. a traceback stack trace
!                     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