Skip to content

Fix handling of maxtasksperchild in ParallelExt for better compatibil… #1939

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions qlib/utils/paral.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class ParallelExt(Parallel):
def __init__(self, *args, **kwargs):
maxtasksperchild = kwargs.pop("maxtasksperchild", None)
super(ParallelExt, self).__init__(*args, **kwargs)
if isinstance(self._backend, MultiprocessingBackend):
if isinstance(self._backend, MultiprocessingBackend) and maxtasksperchild is not None:
# 2025-05-04 joblib released version 1.5.0, in which _backend_args was removed and replaced by _backend_kwargs.
# Ref: https://github.com/joblib/joblib/pull/1525/files#diff-e4dff8042ce45b443faf49605b75a58df35b8c195978d4a57f4afa695b406bdc
if joblib.__version__ < "1.5.0":
self._backend_args["maxtasksperchild"] = maxtasksperchild # pylint: disable=E1101
else:
# Check for attribute existence instead of version comparison to be more robust
if hasattr(self, '_backend_kwargs'):
self._backend_kwargs["maxtasksperchild"] = maxtasksperchild # pylint: disable=E1101
elif hasattr(self, '_backend_args'):
self._backend_args["maxtasksperchild"] = maxtasksperchild # pylint: disable=E1101


def datetime_groupby_apply(
Expand Down
Loading