File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 1
1
# Copyright (c) Microsoft Corporation.
2
2
# Licensed under the MIT License.
3
3
4
+ import threading
4
5
from functools import partial
5
6
from threading import Thread
6
7
from typing import Callable , Text , Union
9
10
from joblib ._parallel_backends import MultiprocessingBackend
10
11
import pandas as pd
11
12
12
- from queue import Queue
13
+ from queue import Empty , Queue
13
14
import concurrent
14
15
15
16
from qlib .config import C , QlibConfig
@@ -85,7 +86,17 @@ def close(self):
85
86
86
87
def run (self ):
87
88
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
89
100
if data == self .STOP_MARK :
90
101
break
91
102
data ()
You can’t perform that action at this time.
0 commit comments