Do not implicitly shut down the shared reusable executor#498
Merged
Conversation
All runners with executor=None now share loky's reusable executor singleton, so a finishing (or cancelled) runner must not shut it down: another runner may still be submitting work to it, which raised loky.process_executor.ShutdownExecutorError (seen in the Read the Docs build of tutorial.advanced-topics.md). The executor is only shut down when the user explicitly passes shutdown_executor=True; idle loky workers time out on their own.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow-up to #497. Runners no longer shut down the internally created executor when they finish;
shutdown_executornow defaults to plainFalsesemantics (explicit opt-in), and the docstrings are updated accordingly.Why
Since #497, every runner with
executor=Noneshares loky's reusable executor singleton.BaseRunner._cleanupused to callexecutor.shutdown(wait=True)whenever the runner had created the executor itself (shutdown_executor or (executor is None)), which now kills the shared executor out from under any other runner still using it:This broke the Read the Docs build of #497 while executing
tutorial.advanced-topics.md(a cancelled goal-less runner's cleanup raced with the next runner'sawait runner.task). The race predates #497 on macOS/Windows, where loky was already the default, but docs only execute on Linux so it was never hit.Idle loky workers shut down on their own after their timeout, and loky cleans up at interpreter exit, so nothing leaks.
Testing
ShutdownExecutorErrorbefore, passes now.test_to_dataframefailures that also occur onmain).