Add option to specify an initialization function for 'loky' and 'multiprocessing' backends#1525
Conversation
This reverts commit aa8fc42.
|
Hi @ogrisel - wondering if you have any thoughts on how to test the implementation here correctly? |
|
Hi @ogrisel, this feature request has come up a couple times recently, including in a StackOverflow question: https://stackoverflow.com/questions/78642680/using-load-ext-cudf-pandas-throws-attributeerror Would it be possible to work with a joblib developer to identify how to move forward with tests? |
|
Hi, just wondering is theres been any behind-the-scenes motion on this, as this would be a REALLY handy piece of functionality to have for pre-seeding workers with large, constant, but procedurally generated/loaded datasets at the start of a large number of jobs. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1525 +/- ##
==========================================
- Coverage 95.54% 95.50% -0.04%
==========================================
Files 46 46
Lines 7741 7838 +97
==========================================
+ Hits 7396 7486 +90
- Misses 345 352 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ogrisel
left a comment
There was a problem hiding this comment.
Thanks for finalizing this PR. It appears that we have a problem with what we test, though.
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
ogrisel
left a comment
There was a problem hiding this comment.
LGTM. Hopefully the new pid-based assert statement will not randomly fail in case some workers take too long to start up compared to others.
If that happen we will have to rewrite those new tests to make them more robust to such race conditions.
|
Let's wait for the CI to go through and maybe trigger it a few consecutive times before merging. |
|
This does not seem stable because the first worker fetches the second job between the time where the initializer has been run and the time where the second worker would take the job.
|
|
What is the expected behaviour when Quickly trying with loky you get import math
from joblib import Parallel, delayed
def initializer(): 1/0
Parallel(n_jobs=2, initializer=initializer)(delayed(math.sqrt)(i*i) for i in range(10))DetailsWith multiprocessing you get an infinite loop of error messages until you do Control-C (the behaviour is similar when using import math
from joblib import Parallel, delayed
def initializer(): 1/0
Parallel(n_jobs=2, backend='multiprocessing', initializer=initializer)(delayed(math.sqrt)(i*i) for i in range(10))Details |
|
For the behavior in case of errors, I think this is backend-specific and I would like to say I propose to merge the PR as is, and we can always improve testing in a follow up PR if we feel this is necesary. |
|
Thanks a lot @shwina, for the proposal and for your patience !!! |
Closes #381
This PR adds the ability to specify an initialization function that is run once per worker process when using the
'loky'and'multiprocessing'backends.Usage: