Skip to content

Commit 7acb4f3

Browse files
authored
Fix Async Call (#1869)
1 parent 431f574 commit 7acb4f3

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

qlib/utils/paral.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
import threading
45
from functools import partial
56
from threading import Thread
67
from typing import Callable, Text, Union
@@ -9,7 +10,7 @@
910
from joblib._parallel_backends import MultiprocessingBackend
1011
import pandas as pd
1112

12-
from queue import Queue
13+
from queue import Empty, Queue
1314
import concurrent
1415

1516
from qlib.config import C, QlibConfig
@@ -85,7 +86,17 @@ def close(self):
8586

8687
def run(self):
8788
while True:
88-
data = self._q.get()
89+
# NOTE:
90+
# atexit will only trigger when all the threads ended. So it may results in deadlock.
91+
# So the child-threading should actively watch the status of main threading to stop itself.
92+
main_thread = threading.main_thread()
93+
if not main_thread.is_alive():
94+
break
95+
try:
96+
data = self._q.get(timeout=1)
97+
except Empty:
98+
# NOTE: avoid deadlock. make checking main thread possible
99+
continue
89100
if data == self.STOP_MARK:
90101
break
91102
data()

0 commit comments

Comments
 (0)