summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-20 15:18:04 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-20 15:18:04 (GMT)
commit54ec61ea6e0e5eab62309f1c238af19dda77b607 (patch)
treee3f9131ceb101e1cc8e9f281ccc882daddd60218 /Lib
parent2390104d81fb90c525fb353589837fc66837e5ff (diff)
downloadcpython-54ec61ea6e0e5eab62309f1c238af19dda77b607.zip
cpython-54ec61ea6e0e5eab62309f1c238af19dda77b607.tar.gz
cpython-54ec61ea6e0e5eab62309f1c238af19dda77b607.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/threading.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 5fc149d..7b07265 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()