From d75564d514f2506c8a14291628cd7ca9980f72f2 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Sat, 13 Jul 2024 22:13:55 +0300 Subject: [PATCH] Fix "can't create new thread at interpreter shutdown" errors (known issue with Python 3.12.0 and other versions) --- clearml/utilities/process/mp.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clearml/utilities/process/mp.py b/clearml/utilities/process/mp.py index 6a1d95e6..4b9b831c 100644 --- a/clearml/utilities/process/mp.py +++ b/clearml/utilities/process/mp.py @@ -527,6 +527,13 @@ class BackgroundMonitor(object): if isinstance(self._thread, Thread): if self._thread_pid == os.getpid(): return + + # make sure we start the metrics thread pools before starting the daemon thread + # workaround for: https://github.com/python/cpython/issues/113964 + from ...backend_interface.metrics.interface import Metrics + # noinspection PyProtectedMember + Metrics._initialize_upload_pools() + self._thread_pid = os.getpid() self._thread = Thread(target=self._daemon) self._thread.daemon = True