From 8081f98a101d5684d2bd4e2546d6f30414a2d3e8 Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Sun, 18 Mar 2012 14:38:27 -0700 Subject: [PATCH] Ensure threading._shutdown gets patched too Since threading can get imported multiple times, ensure that the _shutdown symbol is patched so the _MainThread matches what is in _active. This patch fill fix the KeyError on exit under Python 2.7 --- eventlet/green/threading.py | 2 +- tests/patcher_test.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/eventlet/green/threading.py b/eventlet/green/threading.py index 4ac725a..bc13c8a 100644 --- a/eventlet/green/threading.py +++ b/eventlet/green/threading.py @@ -6,7 +6,7 @@ from eventlet.support import greenlets as greenlet __patched__ = ['_start_new_thread', '_allocate_lock', '_get_ident', '_sleep', 'local', 'stack_size', 'Lock', 'currentThread', - 'current_thread', '_after_fork'] + 'current_thread', '_after_fork', '_shutdown'] __orig_threading = patcher.original('threading') __threadlocal = __orig_threading.local() diff --git a/tests/patcher_test.py b/tests/patcher_test.py index 44564dc..750d72a 100644 --- a/tests/patcher_test.py +++ b/tests/patcher_test.py @@ -383,6 +383,14 @@ print len(threading._active) self.assert_(lines[0].startswith('<_GreenThread'), lines[0]) self.assertEqual(lines[1], "1", lines[1]) + def test_keyerror(self): + new_mod = """import eventlet +eventlet.monkey_patch() +""" + self.write_to_tempfile("newmod", new_mod) + output, lines = self.launch_subprocess('newmod') + self.assertEqual(len(lines), 1, "\n".join(lines)) + class GreenThreadWrapper(ProcessBase): prologue = """import eventlet