From 425267ebf30ecc585974d25a5110fc49de4dd05f Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Wed, 31 May 2023 13:45:34 -0500 Subject: [PATCH 1/3] Avoid a busy wait --- swagger_server/__main__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/swagger_server/__main__.py b/swagger_server/__main__.py index 90f10e17..d876b088 100644 --- a/swagger_server/__main__.py +++ b/swagger_server/__main__.py @@ -120,10 +120,7 @@ def start_consumer(thread_queue, db_instance): topo_json = json.loads(topology) manager.add_topology(topo_json) - while True: - if thread_queue.empty(): - continue - + while not thread_queue.empty(): msg = thread_queue.get() logger.debug("MQ received message:" + str(msg)) From b2186a03483befe0b6360ea01f0787a537672e5b Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Thu, 1 Jun 2023 09:07:36 -0500 Subject: [PATCH 2/3] Restore the original looping condition --- swagger_server/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swagger_server/__main__.py b/swagger_server/__main__.py index d876b088..26be9d9c 100644 --- a/swagger_server/__main__.py +++ b/swagger_server/__main__.py @@ -120,7 +120,7 @@ def start_consumer(thread_queue, db_instance): topo_json = json.loads(topology) manager.add_topology(topo_json) - while not thread_queue.empty(): + while True: msg = thread_queue.get() logger.debug("MQ received message:" + str(msg)) From fae1104c330e9cd04bdb234edd8780c01e0fa4fd Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Thu, 1 Jun 2023 09:08:47 -0500 Subject: [PATCH 3/3] Add a note about a blocking call --- swagger_server/__main__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/swagger_server/__main__.py b/swagger_server/__main__.py index 26be9d9c..ad90f9fd 100644 --- a/swagger_server/__main__.py +++ b/swagger_server/__main__.py @@ -121,6 +121,7 @@ def start_consumer(thread_queue, db_instance): manager.add_topology(topo_json) while True: + # Queue.get() will block until there's an item in the queue. msg = thread_queue.get() logger.debug("MQ received message:" + str(msg))