Fix stop of loopingcall

Patch [1] for switched to use eventlet Event for loopingcall events.

It may now happen that stop event is sent when other event was
already sent and loopingcall is already not running.
That cause AssertionError in eventlet.event module.

To avoid that, we should check if if loopingcall is
running before sending _abort.set().

[1] https://review.openstack.org/#/c/611807/

Closes-Bug #1800879

Change-Id: I28ad3bdb51a20350c90dee4420058c30946897e5
This commit is contained in:
Slawek Kaplonski 2018-10-31 22:44:23 +01:00
parent 6694bd16be
commit 3e08f3375e
2 changed files with 12 additions and 1 deletions

View File

@ -121,7 +121,8 @@ class LoopingCallBase(object):
return not self._abort.is_set()
def stop(self):
self._abort.set()
if self._running:
self._abort.set()
def wait(self):
return self.done.wait()

View File

@ -100,6 +100,16 @@ class LoopingCallTestCase(test_base.BaseTestCase):
wait_ev.set()
timer.wait()
def test_no_double_stop(self):
def _raise_it():
raise loopingcall.LoopingCallDone(False)
timer = loopingcall.FixedIntervalLoopingCall(_raise_it)
timer.start(interval=0.5)
timer.stop()
timer.stop()
def test_repeat(self):
self.num_runs = 2