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

Avoid using internal functions/object with multiprocessing #843

Merged
merged 1 commit into from
Sep 22, 2023

Conversation

gcalacoci
Copy link
Contributor

A Multiprocessing start method is the technique used by the Multiprocessing library to start child processes in Python.

There are three start methods:

  • spawn: start a new Python process.
  • fork: copy a Python process from an existing process.
  • forkserver: new process from which future forked processes will be copied.

Each OS has a list of supported start methods:

  • Windows (win32): spawn
  • MacOS (darwin): spawn (default), fork, forkserver.
  • Linux (unix): spawn, fork (default), forkserver.

Spawn not only is the most supported, but as per recent investigations of the devs of the Multiprocessing library, is the most secure on all the OS.

Spawn method makes use of the Pickle library for starting the new subprocesses and Pickle is unable to process internal objects and functions.

Get rid an internal function (handler inside the make_logging_handler method of the Command class) and use a callable object instead.

Consider substituting internal objects and functions with Pickle compliant options all around the code and eventually enforce the usage of the spawn method.

A Multiprocessing start method is the technique used
by the Multiprocessing library to start child processes in Python.

There are three start methods:

* spawn: start a new Python process.
* fork: copy a Python process from an existing process.
* forkserver: new process from which future forked processes will be copied.

Each OS has a list of supported start methods:
* Windows (win32): spawn
* MacOS (darwin): spawn (default), fork, forkserver.
* Linux (unix): spawn, fork (default), forkserver.

Spawn not only is the most supported, but as per recent investigations
of the devs of the Multiprocessing library, is the most secure on all
the OS.

Spawn method makes use of the Pickle library for starting the new
subprocesses and Pickle is unable to process internal objects and
functions.

Get rid an internal function (handler inside the make_logging_handler
method of the Command class) and use a callable object instead.

Consider substituting internal objects and functions with Pickle
compliant options all around the code and eventually enforce the usage
of the spawn method.

Signed-off-by: Giulio Calacoci <[email protected]>
@edb-sonar-app
Copy link

edb-sonar-app bot commented Sep 12, 2023

Copy link
Contributor

@mikewallace1979 mikewallace1979 left a comment

Choose a reason for hiding this comment

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

Huge 🙌 for doing the research and experimentation behind this patch.

Consider substituting internal objects and functions with Pickle compliant options all around the code and eventually enforce the usage of the spawn method.

This sounds like the most sensible way forward and something we need to do in a separate ticket, maybe under the general title of Python 3.12 compatibility.

@gcalacoci gcalacoci merged commit 367d5e5 into master Sep 22, 2023
9 checks passed
@gcalacoci gcalacoci deleted the dev/bar-99 branch September 22, 2023 10:47
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.

2 participants