Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Async Call #1869

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions qlib/utils/paral.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

import threading
from functools import partial
from threading import Thread
from typing import Callable, Text, Union
Expand All @@ -9,7 +10,7 @@
from joblib._parallel_backends import MultiprocessingBackend
import pandas as pd

from queue import Queue
from queue import Empty, Queue
import concurrent

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

def run(self):
while True:
data = self._q.get()
# NOTE:
# atexit will only trigger when all the threads ended. So it may results in deadlock.
# So the child-threading should actively watch the status of main threading to stop itself.
main_thread = threading.main_thread()
if not main_thread.is_alive():
break
try:
data = self._q.get(timeout=1)
except Empty:
# NOTE: avoid deadlock. make checking main thread possible
continue
if data == self.STOP_MARK:
break
data()
Expand Down
Loading