From 5958b93755e987f0d071bd2c93a8ef753a69c550 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Thu, 11 Jan 2024 21:28:21 -0600 Subject: [PATCH] Avoid busy wait in bapm_server Queue.get is a blocking call; no need of checking if the queue is non-empty in a loop. https://docs.python.org/3/library/queue.html#queue.Queue.get --- bapm_server/__main__.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bapm_server/__main__.py b/bapm_server/__main__.py index 5fb78163..7d2cedfc 100644 --- a/bapm_server/__main__.py +++ b/bapm_server/__main__.py @@ -34,14 +34,13 @@ def start_consumer(thread_queue, es): t1.start() while True: - if not thread_queue.empty(): - data = thread_queue.get() - if is_json(data): - resp = es.index(index="measurement-index", id=MSG_ID, document=data) - print(resp["result"]) - MSG_ID += 1 - else: - logger.info("Received non-JSON data. Not saving to ElasticSearch.") + data = thread_queue.get() + if is_json(data): + resp = es.index(index="measurement-index", id=MSG_ID, document=data) + print(resp["result"]) + MSG_ID += 1 + else: + logger.info("Received non-JSON data. Not saving to ElasticSearch.") def main():