From 4706b6c2959413235c0c3a0b9410a04c4e6870ee Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Wed, 6 May 2020 15:04:07 +0200 Subject: [PATCH] Monkey patch original current_thread _active Monkey patch the original current_thread to use the up-to-date _active global variable. This solution is based on that documented at: https://github.com/eventlet/eventlet/issues/592 Change-Id: Icb26c43a71accdb4658ad6087fb3226f9a1090c0 Story: 2007614 --- os_ken/lib/hub.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/os_ken/lib/hub.py b/os_ken/lib/hub.py index c5da9c80..cb807f8e 100644 --- a/os_ken/lib/hub.py +++ b/os_ken/lib/hub.py @@ -44,11 +44,20 @@ if HUB_TYPE == 'eventlet': import traceback getcurrent = eventlet.getcurrent - patch = eventlet.monkey_patch sleep = eventlet.sleep listen = eventlet.listen connect = eventlet.connect + def patch(thread=True): + eventlet.monkey_patch(thread=thread) + if thread: + # Monkey patch the original current_thread to use the up-to-date _active + # global variable. See https://bugs.launchpad.net/bugs/1863021 and + # https://github.com/eventlet/eventlet/issues/592 + import __original_module_threading as orig_threading # noqa + import threading # noqa + orig_threading.current_thread.__globals__['_active'] = threading._active + def spawn(*args, **kwargs): raise_error = kwargs.pop('raise_error', False)