Avoid calling eventlet.event.Event.reset()

The eventlet maintainers have made it clear that calling reset() on an
Event is not recommended:

715b2ced52

We don't really need to resend the event to wake up threads, because
Event.wait() will return immediately once the event has been sent. So
just rely on the internal _set flag to tell us whether we need to send
the event.

Change-Id: I466aa7cb64308e018598c3bb63a9d0cfbc833adc
This commit is contained in:
Zane Bitter 2019-01-02 10:14:47 +13:00
parent cc8b51e1e1
commit 14a53c4d8a
2 changed files with 6 additions and 9 deletions

View File

@ -165,11 +165,9 @@ class EventletEvent(object):
isSet = is_set
def set(self):
if self._set:
self._event.reset()
self._set = True
self._event.send(True)
if not self._set:
self._set = True
self._event.send(True)
def wait(self, timeout=None):
with timeutils.StopWatch(timeout) as sw:

View File

@ -146,12 +146,11 @@ class EventletUtilsTest(test_base.BaseTestCase):
self.assertTrue(hasattr(e_event, method))
# Ensure set() allows multiple invocations, same as in
# threading implementation. Must call reset on underlying
# Event before reusing it
# threading implementation.
e_event.set()
self.assertEqual(0, mock_eventlet.event.Event().reset.call_count)
self.assertTrue(e_event.isSet())
e_event.set()
self.assertEqual(1, mock_eventlet.event.Event().reset.call_count)
self.assertTrue(e_event.isSet())
def test_event_no_timeout(self):
event = eventletutils.EventletEvent()