Repository navigation
Configurable multiprocessing context - #3763
Conversation
| def get_context(): | ||
| """ Return the current multiprocessing context.""" | ||
| if sys.platform == "win32" or sys.version_info.major == 2: | ||
| # Just do the default, since we can't change it: |
There was a problem hiding this comment.
I feel like it should be an error if multiprocessing.context is set to a value that doesn't work on the platform
There was a problem hiding this comment.
The downside of that is you can't share a configuration file across platforms. If this is acceptable, I can make that change.
Alternatively... python warning/warning log message if the option is used on unsupported platform, instead of error?
There was a problem hiding this comment.
A warning can be an acceptable compromise.
|
Added a warning. |
|
cc @jcrist it would be good to get your thoughts on this issue |
| if sys.platform == "win32" or sys.version_info.major == 2: | ||
| # Just do the default, since we can't change it: | ||
| if config.get("multiprocessing.context", None) is not None: | ||
| warn(_CONTEXT_UNSUPPORTED, UserWarning) |
There was a problem hiding this comment.
I suspect that this will become annoying for users that switch between Python 2 and 3 and want to specify a multiprocessing context in Python 3. I appreciate that this concern is probably in direct contraction with the "lets warn users if we're doing something silently" concern, but I still anticipate that we'll get some confusion about it.
Does anyone have thoughts on what the right thing to do here is?
There was a problem hiding this comment.
- People who set this option know what they're doing, probably, so are less likely to be confused.
- Given better default (the follow up ticket), less people will be interested in setting this.
There was a problem hiding this comment.
What about just erroring? It's not supported on Python 2. So we probably shouldn't let people set this there.
Edit: Guess this was nixed above.
| if pool is None: | ||
| pool = multiprocessing.Pool(num_workers, | ||
| initializer=initialize_worker_process) | ||
| context = get_context() |
There was a problem hiding this comment.
If someone uses forkserver then does a new server get spawned every time here, or are they reused between calls?
There was a problem hiding this comment.
Contexts are singleton in Python at the moment.
There was a problem hiding this comment.
Are you imagine caching contexts, @mrocklin? Can see that being important particularly if we want re-entrant behavior.
There was a problem hiding this comment.
We currently do this once at import time for dask.distributed. The context is global.
There was a problem hiding this comment.
So create all possible contexts at import and then choose between them here? Maybe add them to a dictionary? Other thoughts?
There was a problem hiding this comment.
Python already has singleton contexts, there's no need to duplicate that behavior.
There was a problem hiding this comment.
Indeed
In [1]: import multiprocessing
In [2]: multiprocessing.get_context('forkserver') is multiprocessing.get_context('forkserver')
Out[2]: True|
In distributed we create one context on import. If the user wants to
switch then they need to restart the process. I haven't run into a
situation where this was a limitation and people wanted to use multiple
contexts in a single session.
…On Mon, Jul 16, 2018 at 1:40 PM, jakirkham ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In dask/multiprocessing.py
<#3763 (comment)>:
> @@ -148,8 +166,9 @@ def get(dsk, keys, num_workers=None, func_loads=None, func_dumps=None,
"""
pool = config.get('pool', None)
if pool is None:
- pool = multiprocessing.Pool(num_workers,
- initializer=initialize_worker_process)
+ context = get_context()
So create all possible contexts at import and then choose between them
here? Maybe add them to a dictionary? Other thoughts?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3763 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszONNI0jrsd4-TM2VdzQ2sTasqWrGks5uHN4UgaJpZM4VP-Nv>
.
|
|
Just to recap, only remaining issue seems to be whether to warn or error on unsupported configurations? |
|
@jakirkham do you want to handle this within a release soon or wait on it for a larger 0.X.0 release? |
|
Personally I'd rather fix up any test failures and cut a patch release (ideally today). That said, if others have thoughts on this, feel free to weigh in on issue ( #3789 ). |
|
To be clear the question wasn't "do you want to fix these problems" there are no problems in this PR, just a decision that needs to be made. Currently this PR is lingering because no one has made a solid decision. The question was "do we want to make this decision and, if so, do we want to delay making it until after the release". Given your answer I take it that you think that no, we should not answer this question yet, we should wait until after the release. |
|
@jcrist if you have a moment it would be good to get your thoughts on this |
Apologies for the delay in getting to this. To summarize (for my own understanding), there are a few different ways a user could have an unsupported configuration:
I think warning and falling back to the default for that platform in both cases makes sense to me. As a user I'd want to know if my default is being ignored, but I don't think I'd want my configuration (especially if it's a global configuration setup by an administrator) to prevent dask from working. |
|
Progress, but there's a failing test. It seems like it's completely unrelated to this branch though :( |
|
This passes all checks, and can be merged. |
|
Merging this. Thanks for your patience @itamarst |
Fixes #3758.
flake8 dask