X Tutup
The Wayback Machine - https://web.archive.org/web/20250607040153/https://github.com/python/cpython/pull/9627
Skip to content

bpo-34837: Multiprocessing.Pool API Extension - Pass Data to Workers w/o Globals #9627

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 5 commits into
base: main
Choose a base branch
from

Conversation

seanharr11
Copy link

@seanharr11 seanharr11 commented Sep 28, 2018

Proposing a new kwarg in the __init__() method of multiprocessing.Pool named expect_initret.

This kwarg defaults to False. When set to True, the return value of the initializer function is passed to the function we are applying (i.e. func in Pool.map(func, ls)), as a kwarg named initret.

This PR includes thorough test coverage, and provides backwards compatibility (at least in Python3.x).

See this blog post for example use cases, as well as an initial defense for why this makes the multiprocessing.Pool API more approachable, to more Python end-users, and augments the library.

https://bugs.python.org/issue34837

@seanharr11 seanharr11 requested a review from 1st1 as a code owner September 28, 2018 20:14
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@seanharr11 seanharr11 changed the title bpo-34837: Multiprocessing.Pool API Extension - Non-Global Initialization of Workers bpo-34837: Multiprocessing.Pool API Extension - Pass Data to Workers w/o Globals Sep 28, 2018
Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

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

Add a doc patch.
If possible (see devguide), add a blurb: one short paragraph, up to 3 sentences.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@seanharr11
Copy link
Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@terryjreedy: please review the changes made to this pull request.

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

As I indicated on the mailing-list, I am still opposed to the general idea (though, congratulations for making a full-fledged PR). I am open to revise my opinion if there are enough core developers in favour of the idea, but that doesn't seem to be the case currently...

@@ -264,7 +282,10 @@ def _maintain_pool(ctx, Process, processes, pool, inqueue, outqueue,
"""Clean up any exited workers and start replacements for them.
"""
if Pool._join_exited_workers(pool):
Pool._repopulate_pool_static(ctx, Process, processes, pool,
Pool.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the PR. There seems to white spaces in this line and causes make patchcheck to fail in CI. Please remove them or run make patchcheck locally from the source directory that will fix this for you automatically.

Relevant make patchcheck output :

Getting base branch for PR ... upstream/master
Getting the list of files that have been added/changed ... 5 files
Fixing Python file whitespace ... 1 file:
  Lib/multiprocessing/pool.py
Fixing C file whitespace ... 0 files
Fixing docs whitespace ... 0 files
Docs modified ... yes
Misc/ACKS updated ... NO
Misc/NEWS.d updated with `blurb` ... NO
configure regenerated ... not needed
pyconfig.h.in regenerated ... not needed

@seanharr11
Copy link
Author

@pitrou see my recent email response to @njsmith 's suggestion. I think we are on to something there...

@TommyDew42
Copy link

@seanharr11 I came across your blog about multiprocessing. Seems this PR is still in progress. What blockers do we have? I'm curious if the issue in your blog still exists in the latest version of python?

@seanharr11
Copy link
Author

To my knowledge, this issue still exists in the latest version of Python3. Per comments above, we were looking for consensus from core developers to merge this in.

Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting change review stale Stale PR or inactive for long period of time. topic-multiprocessing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants
X Tutup