From 712d974c8ca5b5c6230d06905c885ff33793d3b1 Mon Sep 17 00:00:00 2001 From: qianduoduo0904 Date: Tue, 23 Aug 2022 16:55:30 +0800 Subject: [PATCH] Fix hang when calling `exit()` in interpreter --- mars/core/entity/executable.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mars/core/entity/executable.py b/mars/core/entity/executable.py index e880681dce..e0064a634b 100644 --- a/mars/core/entity/executable.py +++ b/mars/core/entity/executable.py @@ -25,6 +25,9 @@ from ..mode import enter_mode +main_thread = threading.current_thread() + + class DecrefRunner: def __init__(self): self._decref_thread = None @@ -66,11 +69,16 @@ def stop(self): self._queue.put_nowait((None, None, None)) self._decref_thread.join(1) - def put(self, key: str, session_ref: ref): + def put(self, key: str, session_ref: ref) -> concurrent.futures.Future: + fut = concurrent.futures.Future() + + if not main_thread.is_alive(): + fut.set_result(None) + return fut + if self._decref_thread is None: self.start() - fut = concurrent.futures.Future() self._queue.put_nowait((key, session_ref, fut)) return fut