python-zk/kazoo — pull request #183 by wickman (2014-03-26 00:33:03+00:00)
Title: Fix atexit handling for kazoo threading handler.

See http://stackoverflow.com/questions/2572172/referencing-other-modules-in-atexit

Referencing Queue directly in the atexit-registered self.stop is dangerous and actually results in test failures in our CI environment:

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/private/var/folders/4d/9tz0cd5n2n7947xs21gspsxc0000gp/T/tmpSNllNO/.deps/kazoo-1.3.1-py2.6.egg/kazoo/handlers/threading.py", line 248, in stop
self.callback_queue = Queue.Queue()
AttributeError: 'NoneType' object has no attribute 'Queue'

This fixes using a similar approach to the stackoverflow post which just memoizes Queue.Queue so that it isn't garbage collected out from underneath us before the atexit handlers run.