diff --git a/.github/workflows/mac_arm64.yml b/.github/workflows/mac_arm64.yml index c5a8fecd63..38dcbcf946 100644 --- a/.github/workflows/mac_arm64.yml +++ b/.github/workflows/mac_arm64.yml @@ -33,6 +33,7 @@ jobs: if: ${{ needs.call-check-pr-status.outputs.should_continue == 'true' }} runs-on: macos-latest strategy: + fail-fast: false matrix: build_type: [debug, release] steps: diff --git a/core/src/ten_runtime/binding/python/interface/ten_runtime/global_thread_manager.py b/core/src/ten_runtime/binding/python/interface/ten_runtime/global_thread_manager.py index 1e68ed874c..a46b30b21a 100644 --- a/core/src/ten_runtime/binding/python/interface/ten_runtime/global_thread_manager.py +++ b/core/src/ten_runtime/binding/python/interface/ten_runtime/global_thread_manager.py @@ -18,25 +18,26 @@ class GlobalThreadManager: _instance: "GlobalThreadManager | None" = None _lock: threading.Lock = threading.Lock() + _ref_count: int + _main_thread: threading.Thread | None + _main_loop: asyncio.AbstractEventLoop | None + _stop_event: asyncio.Event + _loop_ready_event: threading.Event + def __new__(cls): if cls._instance is None: with cls._lock: if cls._instance is None: - cls._instance = super().__new__(cls) - cls._instance._initialized = False + instance = super().__new__(cls) + instance._ref_count = 0 + instance._main_thread = None + instance._main_loop = None + instance._stop_event = asyncio.Event() + instance._loop_ready_event = threading.Event() + # Publish only after initialization, while holding the lock. + cls._instance = instance return cls._instance - def __init__(self): - if self._initialized: - return - - self._ref_count: int = 0 - self._main_thread: threading.Thread | None = None - self._main_loop: asyncio.AbstractEventLoop | None = None - self._stop_event: asyncio.Event = asyncio.Event() - self._loop_ready_event: threading.Event = threading.Event() - self._initialized: bool = True - def reset(self): with self._lock: self._ref_count = 0 @@ -44,7 +45,6 @@ def reset(self): self._main_loop = None self._stop_event = asyncio.Event() self._loop_ready_event = threading.Event() - self._initialized = True def get_or_start_thread( self, ten_env: "TenEnv"