Skip to content

Commit 763659a

Browse files
author
Aliaksandr Trush
committed
do not raise error if service already terminated
1 parent cd0509b commit 763659a

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

reportportal_client/service_async.py

Lines changed: 18 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,26 @@ 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+
with self.lock:
152+
logger.debug("Terminating service")
151153

152-
if not self.listener:
153-
raise Error("Service already stopped.")
154+
if not self.listener:
155+
logger.debug("Service already stopped.")
156+
return
154157

155-
self.listener.stop(nowait)
158+
self.listener.stop(nowait)
156159

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
160+
try:
161+
if not nowait:
162+
self._post_log_batch()
163+
except Exception:
164+
if self.error_handler:
165+
self.error_handler(sys.exc_info())
166+
else:
167+
raise
168+
finally:
169+
self.queue = None
170+
self.listener = None
168171

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

0 commit comments

Comments
 (0)