Skip to content

Commit

Permalink
fix: fix a bug that causes consume(nowait=False) to hang forever
Browse files Browse the repository at this point in the history
  • Loading branch information
furkan-bilgin committed Nov 11, 2024
1 parent 09dbd67 commit ede5f9d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/daq/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,24 @@ def __init__(
self.info = self._create_info()

def consume(self, nowait=True):
# consume messages from the queue
"""
Consumes messages from the message_in queue.
If nowait is True, it will consume the message immediately.
Otherwise, it will wait until a message is available.
"""

def _process_message(message):
if not self.handle_message(message):
self.message_in.put(message)

# Return immediately after consuming the message
if not nowait:
_process_message(self.message_in.get())
return

while True:
try:
if nowait:
message = self.message_in.get_nowait()
else:
message = self.message_in.get()
if not self.handle_message(message):
self.message_in.put(message)
_process_message(self.message_in.get_nowait())
except Empty:
break

Expand Down

0 comments on commit ede5f9d

Please sign in to comment.