Backport r57216 (see issue #1731).
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.

This also backports other small changes to this file, essentially making
it identical to the trunk version.
1 file changed