From c8173d2e40f52f585f735c16ce84aaf2c450373a Mon Sep 17 00:00:00 2001 From: ppigazzini Date: Thu, 4 Apr 2024 14:41:12 +0200 Subject: [PATCH] Mitigate Python 3.12 shutdown RuntimeError Python 3.12 introduced a bug during the interpreter shutdown, see: - issue https://github.com/python/cpython/pull/104826 - bugfix https://github.com/python/cpython/pull/117029 With Python 3.12.3, this change could potentially be reverted (after testing). --- server/fishtest/rundb.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server/fishtest/rundb.py b/server/fishtest/rundb.py index de0ddf623..409597de0 100644 --- a/server/fishtest/rundb.py +++ b/server/fishtest/rundb.py @@ -361,8 +361,16 @@ def get_run(self, r_id): return None def start_timer(self): - self.timer = threading.Timer(1.0, self.flush_buffers) - self.timer.start() + try: + self.timer = threading.Timer(1.0, self.flush_buffers) + self.timer.start() + except RuntimeError as e: + # Mitigation for a 3.12 bug during the interpreter shutdown, see: + # - issue https://github.com/python/cpython/pull/104826 + # - bugfix https://github.com/python/cpython/pull/117029 + # With python 3.12.3 the try except block could be potentially removed. + if "interpreter shutdown" not in str(e): + raise def buffer(self, run, flush): with self.run_cache_lock: