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
This commit is contained in:
parent
c568717706
commit
fde490f22d
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue