Skip to content

Commit

Permalink
Move messages_processed into instance state for ProcessWorker
Browse files Browse the repository at this point in the history
psarma89 committed Apr 15, 2021
1 parent 4bafcfa commit fbc716e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pyqs/worker.py
Original file line number Diff line number Diff line change
@@ -189,22 +189,24 @@ def __init__(self, internal_queue, interval, connection_args=None, *args,
self.internal_queue = internal_queue
self.interval = interval
self._messages_to_process_before_shutdown = 100
self.messages_processed = 0

def run(self):
# Set the child process to not receive any keyboard interrupts
signal.signal(signal.SIGINT, signal.SIG_IGN)

logger.info("Running ProcessWorker, pid: {}".format(os.getpid()))
messages_processed = 0

while not self.should_exit.is_set() and self.parent_is_alive():
processed = self.process_message()
if processed:
messages_processed += 1
self.messages_processed += 1
time.sleep(self.interval)
else:
# If we have no messages wait a moment before rechecking.
time.sleep(0.001)
if messages_processed >= self._messages_to_process_before_shutdown:
if self.messages_processed \
>= self._messages_to_process_before_shutdown:
self.shutdown()

def process_message(self):

0 comments on commit fbc716e

Please sign in to comment.