X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ricxappframe%2Fxapp_rmr.py;h=4e5e63585f07e11a97384ec3a7143e14e3750cc5;hb=refs%2Fchanges%2F28%2F3128%2F4;hp=ab13369af7aa233a4298a08f87182175113854b9;hpb=21f659c694968e95ad4e1a568538a586c5291b62;p=ric-plt%2Fxapp-frame-py.git diff --git a/ricxappframe/xapp_rmr.py b/ricxappframe/xapp_rmr.py index ab13369..4e5e635 100644 --- a/ricxappframe/xapp_rmr.py +++ b/ricxappframe/xapp_rmr.py @@ -66,14 +66,16 @@ class RmrLoop: time.sleep(0.1) # Private - self._keep_going = True - self._last_ran = time.time() + self._keep_going = True # used to tell this thread to stop it's work + self._last_ran = time.time() # used for healthcheck + self._loop_is_running = False # used in stop to know when it's safe to kill the mrc # start the work loop mdc_logger.debug("Starting loop thread") def loop(): mdc_logger.debug("Work loop starting") + self._loop_is_running = True while self._keep_going: # read our mailbox @@ -86,15 +88,24 @@ class RmrLoop: self._last_ran = time.time() + self._loop_is_running = False + self._thread = Thread(target=loop) self._thread.start() def stop(self): """ sets a flag that will cleanly stop the thread - note, this does not yet have a use yet for xapps to call, however this is very handy during unit testing. """ + mdc_logger.debug("Stopping rmr thread. Waiting for last iteration to finish..") self._keep_going = False + # wait until the current batch of messages is done, then kill the rmr connection + # note; I debated putting this in "loop" however if the while loop was still going setting mrc to close here would blow up any processing still currently happening + # probably more polite to at least finish the current batch and then close. So here we wait until the current batch is done, then we kill the mrc + while self._loop_is_running: + pass + mdc_logger.debug("Closing rmr connection") + rmr.rmr_close(self.mrc) def healthcheck(self, seconds=30): """