From 0f28fe7144ef6d772b657c86b186067cf106e384 Mon Sep 17 00:00:00 2001 From: codingl2k1 <138426806+codingl2k1@users.noreply.github.com> Date: Fri, 29 Nov 2024 02:15:56 +0100 Subject: [PATCH] BUG: Fix crash when exiting the daemon thread (#116) --- python/xoscar/backends/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/xoscar/backends/core.py b/python/xoscar/backends/core.py index 4a0dade..b4638a1 100644 --- a/python/xoscar/backends/core.py +++ b/python/xoscar/backends/core.py @@ -16,6 +16,7 @@ from __future__ import annotations import asyncio +import atexit import copy import logging import threading @@ -216,6 +217,7 @@ class _RefHolder: _close_loop = asyncio.new_event_loop() _close_thread = threading.Thread(target=_close_loop.run_forever, daemon=True) _close_thread.start() + atexit.register(_close_loop.call_soon_threadsafe, _close_loop.stop) def __init__(self): self._thread_local = threading.local()