Index: Lib/threading.py =================================================================== --- Lib/threading.py (revision 29955) +++ Lib/threading.py (revision 29956) @@ -758,18 +758,17 @@ def _exitfunc(self): self._Thread__stop() - - wait = self.waitForThreadsOnExitFunc() - if wait: - t = _pickSomeNonDaemonThread() - if t: - if __debug__: - self._note("%s: waiting for other threads", self) - while t: - t.join() - t = _pickSomeNonDaemonThread() - if __debug__: - self._note("%s: exiting", self) + + t = _pickSomeNonDaemonThread() + if t: + wait = self.waitForThreadsOnExitFunc() + if wait and __debug__: + self._note("%s: waiting for other threads", self) + while t and wait: + t.join() + t = _pickSomeNonDaemonThread() + if __debug__: + self._note("%s: exiting", self) self._Thread__delete()