Skip to content

Configurable multiprocessing context - #3763

Merged
mrocklin merged 9 commits into
dask:masterfrom
itamarst:configurable-multiprocessing-context
Sep 20, 2018
Merged

mrocklin merged 9 commits into
dask:masterfrom
itamarst:configurable-multiprocessing-context

Conversation

@itamarst

@itamarst itamarst commented Jul 14, 2018 •

Copy link
Copy Markdown
Contributor

Fixes #3758.

  • Tests added / passed
  • Passes flake8 dask

Comment thread dask/multiprocessing.py
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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel like it should be an error if multiprocessing.context is set to a value that doesn't work on the platform

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A warning can be an acceptable compromise.

@itamarst

Copy link
Copy Markdown
Contributor Author

Added a warning.

@mrocklin

Copy link
Copy Markdown
Member

cc @jcrist it would be good to get your thoughts on this issue

Comment thread dask/multiprocessing.py
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. People who set this option know what they're doing, probably, so are less likely to be confused.
  2. Given better default (the follow up ticket), less people will be interested in setting this.

@jakirkham jakirkham Jul 16, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread dask/multiprocessing.py
if pool is None:
pool = multiprocessing.Pool(num_workers,
initializer=initialize_worker_process)
context = get_context()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If someone uses forkserver then does a new server get spawned every time here, or are they reused between calls?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Contexts are singleton in Python at the moment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you imagine caching contexts, @mrocklin? Can see that being important particularly if we want re-entrant behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We currently do this once at import time for dask.distributed. The context is global.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So create all possible contexts at import and then choose between them here? Maybe add them to a dictionary? Other thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Python already has singleton contexts, there's no need to duplicate that behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indeed

In [1]: import multiprocessing

In [2]: multiprocessing.get_context('forkserver') is multiprocessing.get_context('forkserver')
Out[2]: True

@mrocklin

mrocklin commented Jul 16, 2018 via email

Copy link
Copy Markdown
Member

@itamarst

Copy link
Copy Markdown
Contributor Author

Just to recap, only remaining issue seems to be whether to warn or error on unsupported configurations?

@mrocklin

Copy link
Copy Markdown
Member

@jakirkham do you want to handle this within a release soon or wait on it for a larger 0.X.0 release?

@jakirkham

Copy link
Copy Markdown
Member

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 ).

@mrocklin

Copy link
Copy Markdown
Member

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.

@mrocklin

mrocklin commented Aug 2, 2018

Copy link
Copy Markdown
Member

@jcrist if you have a moment it would be good to get your thoughts on this

@jcrist

jcrist commented Aug 2, 2018

Copy link
Copy Markdown
Member

Just to recap, only remaining issue seems to be whether to warn or error on unsupported configurations?

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:

  • Python 2 doesn't allow specifying contexts at all
  • Fork and forkserver aren't available on windows

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.

@itamarst

Copy link
Copy Markdown
Contributor Author

Progress, but there's a failing test. It seems like it's completely unrelated to this branch though :(

@itamarst

Copy link
Copy Markdown
Contributor Author

This passes all checks, and can be merged.

@mrocklin

Copy link
Copy Markdown
Member

Merging this. Thanks for your patience @itamarst

@mrocklin
mrocklin merged commit 7c54224 into dask:master Sep 20, 2018
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.

5 participants