Fix "can't create new thread at interpreter shutdown" errors (known issue with Python 3.12.0 and other versions)

This commit is contained in:
allegroai 2024-07-13 22:13:55 +03:00
parent 74b2b38673
commit d75564d514

View File

@ -527,6 +527,13 @@ class BackgroundMonitor(object):
if isinstance(self._thread, Thread): if isinstance(self._thread, Thread):
if self._thread_pid == os.getpid(): if self._thread_pid == os.getpid():
return 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_pid = os.getpid()
self._thread = Thread(target=self._daemon) self._thread = Thread(target=self._daemon)
self._thread.daemon = True self._thread.daemon = True