From d7385b9fc2cfec672da11d3474d03b70c626c3ac Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Tue, 29 Jul 2025 09:52:37 +0200 Subject: [PATCH] fix timeout for threads --- packages/helpermodules/utils/_thread_handler.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/helpermodules/utils/_thread_handler.py b/packages/helpermodules/utils/_thread_handler.py index 55c3120dd5..cea839dd20 100644 --- a/packages/helpermodules/utils/_thread_handler.py +++ b/packages/helpermodules/utils/_thread_handler.py @@ -1,5 +1,6 @@ import logging from threading import Thread, enumerate +import time from typing import List, Optional log = logging.getLogger(__name__) @@ -26,9 +27,16 @@ def split_chunks(to_split, n): for thread in threads_to_keep: thread.start() - # Wait for all to complete - for thread in threads_to_keep: - thread.join(timeout=timeout) + if threads_to_keep: + if timeout is not None: + start_time = time.monotonic() + while time.monotonic() - start_time < timeout: + if not [t for t in threads_to_keep if t.is_alive()]: + break + time.sleep(0.05) + else: + for thread in threads_to_keep: + thread.join() for thread in threads_to_keep: if thread.is_alive():