From fcdb0a37a859ad564870d78d06705f36122fe006 Mon Sep 17 00:00:00 2001 From: Qing Wang Date: Wed, 5 Jul 2023 12:27:05 +0800 Subject: [PATCH] Fix reset variables in thread safe way. --- fed/cleanup.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fed/cleanup.py b/fed/cleanup.py index 495ff0d..a770094 100644 --- a/fed/cleanup.py +++ b/fed/cleanup.py @@ -67,10 +67,6 @@ def _signal_exit(): break logger.info('Check sending thread was exited.') - global _check_send_thread - _check_send_thread = None - logger.info('Clearing sending queue.') - _sending_obj_refs_q = None def _main_thread_monitor(): @@ -117,3 +113,9 @@ def wait_sending(): if _check_send_thread: notify_to_exit() _check_send_thread.join() + _check_send_thread = None + + # It's safe to reset `_sending_obj_refs_q` as another + # thread is stoped. + global _sending_obj_refs_q + _sending_obj_refs_q = None