Skip to content

Commit 3f503d0

Browse files
author
Yury Krasouski
authored
Merge branch 'master' into bugfix/24-1
2 parents 897d6eb + e00d668 commit 3f503d0

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

reportportal_client/service_async.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def __init__(self, endpoint, project, token, api_base="api/v1",
139139
self.queue = queue.Queue()
140140
self.listener = QueueListener(self.queue, self.process_item)
141141
self.listener.start()
142+
self.lock = threading.Lock()
142143

143144
def terminate(self, nowait=False):
144145
"""Finalize and stop service
@@ -147,24 +148,27 @@ def terminate(self, nowait=False):
147148
nowait: set to True to terminate immediately and skip processing
148149
messages still in the queue
149150
"""
150-
logger.debug("Terminating service")
151+
logger.debug("Acquiring lock for service termination")
152+
with self.lock:
153+
logger.debug("Terminating service")
151154

152-
if not self.listener:
153-
raise Error("Service already stopped.")
155+
if not self.listener:
156+
logger.warning("Service already stopped.")
157+
return
154158

155-
self.listener.stop(nowait)
159+
self.listener.stop(nowait)
156160

157-
try:
158-
if not nowait:
159-
self._post_log_batch()
160-
except Exception:
161-
if self.error_handler:
162-
self.error_handler(sys.exc_info())
163-
else:
164-
raise
165-
finally:
166-
self.queue = None
167-
self.listener = None
161+
try:
162+
if not nowait:
163+
self._post_log_batch()
164+
except Exception:
165+
if self.error_handler:
166+
self.error_handler(sys.exc_info())
167+
else:
168+
raise
169+
finally:
170+
self.queue = None
171+
self.listener = None
168172

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

0 commit comments

Comments
 (0)