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

Add option to specify an initialization function for 'loky' and 'multiprocessing' backends #1525

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

shwina
Copy link

@shwina shwina commented Nov 20, 2023

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:

Parallel(initializer=my_func, initargs=(x, y, z))
# or
with parallel_config(initializer=my_func, initargs=(x, y, z)):
    ...

Comment on lines +2035 to +2036
assert len(queue) == n_jobs
assert all(q == "spam" for q in queue)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ogrisel I'm actually not sure what assertion I can make here (the current assertion seems not always to be true).

I want to test that every process that was started has run its init function.

However, it seems I sometimes reach line #2035 before all processes have been initialized - and by that time, the work has completed by fewer than the number of started processes.

Do you have any suggestions? Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ogrisel -- just a gentle ping about this if you have any suggestions; thanks!

@shwina
Copy link
Author

shwina commented Feb 6, 2024

Hi @ogrisel - wondering if you have any thoughts on how to test the implementation here correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No simple way to pass initializer for process
1 participant