Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/24-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Krasouski authored Apr 14, 2018
2 parents 897d6eb + e00d668 commit 3f503d0
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions reportportal_client/service_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def __init__(self, endpoint, project, token, api_base="api/v1",
self.queue = queue.Queue()
self.listener = QueueListener(self.queue, self.process_item)
self.listener.start()
self.lock = threading.Lock()

def terminate(self, nowait=False):
"""Finalize and stop service
Expand All @@ -147,24 +148,27 @@ def terminate(self, nowait=False):
nowait: set to True to terminate immediately and skip processing
messages still in the queue
"""
logger.debug("Terminating service")
logger.debug("Acquiring lock for service termination")
with self.lock:
logger.debug("Terminating service")

if not self.listener:
raise Error("Service already stopped.")
if not self.listener:
logger.warning("Service already stopped.")
return

self.listener.stop(nowait)
self.listener.stop(nowait)

try:
if not nowait:
self._post_log_batch()
except Exception:
if self.error_handler:
self.error_handler(sys.exc_info())
else:
raise
finally:
self.queue = None
self.listener = None
try:
if not nowait:
self._post_log_batch()
except Exception:
if self.error_handler:
self.error_handler(sys.exc_info())
else:
raise
finally:
self.queue = None
self.listener = None

def _post_log_batch(self):
logger.debug("Posting log batch size: %s", len(self.log_batch))
Expand Down

0 comments on commit 3f503d0

Please sign in to comment.