From: Guido van Rossum Date: Mon, 20 Aug 2007 15:18:04 +0000 (+0000) Subject: Add a hack (originally devised in a slightly different form by Thomas Wouters) X-Git-Tag: v2.6a1~1475 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=54ec61ea6e0e5eab62309f1c238af19dda77b607;p=python Add a hack (originally devised in a slightly different form by Thomas Wouters) to prevent spurious tracebacks when a daemon thread's cleanup happens to wake up when the world around it has already been destroyed. --- diff --git a/Lib/threading.py b/Lib/threading.py index 5fc149dc33..7b07265670 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -446,6 +446,26 @@ class Thread(_Verbose): self.__target(*self.__args, **self.__kwargs) def __bootstrap(self): + # Wrapper around the real bootstrap code that ignores + # exceptions during interpreter cleanup. Those typically + # happen when a daemon thread wakes up at an unfortunate + # moment, finds the world around it destroyed, and raises some + # random exception *** while trying to report the exception in + # __bootstrap_inner() below ***. Those random exceptions + # don't help anybody, and they confuse users, so we suppress + # them. We suppress them only when it appears that the world + # indeed has already been destroyed, so that exceptions in + # __bootstrap_inner() during normal business hours are properly + # reported. Also, we only suppress them for daemonic threads; + # if a non-daemonic encounters this, something else is wrong. + try: + self.__bootstrap_inner() + except: + if self.__daemonic and _sys is None: + return + raise + + def __bootstrap_inner(self): try: self.__started = True _active_limbo_lock.acquire()