From fde490f22d2ed3aacd0590e051b2722cb071d4bd Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Thu, 1 Nov 2018 16:24:45 +0000 Subject: [PATCH] Expose eventlet Event wrapper class We have a need to use the eventlet Event class directly in oslo.service. Currently it is copy-pasted from this project, but we now have a duplicate bug due to that so let's just expose it so one copy can be used in both places. This should be safe as the class implements a stdlib interface so we can't really alter the API, and it's not really private since instances of it are returned to users. Change-Id: If8e7a41f9fe5573a780f9faabdbaf1326631d37a Related-Change: https://review.openstack.org/558879 Related-Bug: 1800879 --- oslo_utils/eventletutils.py | 5 +++-- oslo_utils/tests/test_eventletutils.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/oslo_utils/eventletutils.py b/oslo_utils/eventletutils.py index 46d9ba7a..e5d8822b 100644 --- a/oslo_utils/eventletutils.py +++ b/oslo_utils/eventletutils.py @@ -140,13 +140,14 @@ def is_monkey_patched(module): return _patcher.is_monkey_patched(module) -class _Event(object): +class EventletEvent(object): """A class that provides consistent eventlet/threading Event API. This wraps the eventlet.event.Event class to have the same API as the standard threading.Event object. """ def __init__(self, *args, **kwargs): + super(EventletEvent, self).__init__() self.clear() def clear(self): @@ -173,6 +174,6 @@ class _Event(object): def Event(): if is_monkey_patched("thread"): - return _Event() + return EventletEvent() else: return threading.Event() diff --git a/oslo_utils/tests/test_eventletutils.py b/oslo_utils/tests/test_eventletutils.py index 8e71e814..d72d03a1 100644 --- a/oslo_utils/tests/test_eventletutils.py +++ b/oslo_utils/tests/test_eventletutils.py @@ -128,7 +128,7 @@ class EventletUtilsTest(test_base.BaseTestCase): with mock.patch('oslo_utils.eventletutils.is_monkey_patched', return_value=True): e_event = eventletutils.Event() - self.assertIsInstance(e_event, eventletutils._Event) + self.assertIsInstance(e_event, eventletutils.EventletEvent) t_event = eventletutils.Event() if six.PY3: