From 5152b9a3cc926bf5ae6e2f4bcb9fce53f264e900 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 14 Sep 2022 12:29:07 +0530 Subject: [PATCH] Agent: Use threading.Event instead of flag in send_all_events_to_island.py --- monkey/infection_monkey/send_all_events_to_island.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/monkey/infection_monkey/send_all_events_to_island.py b/monkey/infection_monkey/send_all_events_to_island.py index cd3c449c1..a7260b495 100644 --- a/monkey/infection_monkey/send_all_events_to_island.py +++ b/monkey/infection_monkey/send_all_events_to_island.py @@ -48,17 +48,16 @@ class send_all_events_to_island: self._server_address = server_address self._time_period = time_period - self._should_run_batch_and_send_thread = True + self._stop_batch_and_send_thread = threading.Event() def start(self): - self._should_run_batch_and_send_thread = True self._batch_and_send_thread = threading.Thread( name="SendEventsToIslandInBatchesThread", target=self._manage_event_batches ) self._batch_and_send_thread.start() def _manage_event_batches(self): - while self._should_run_batch_and_send_thread: + while not self._stop_batch_and_send_thread.is_set(): self._send_events_to_island() sleep(self._time_period) @@ -90,5 +89,5 @@ class send_all_events_to_island: self._send_events_to_island() def stop(self): - self._should_run_batch_and_send_thread = False + self._stop_batch_and_send_thread.set() self._batch_and_send_thread.join()