summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing/forkserver.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-97514: Authenticate the forkserver control socket. (GH-99309)Gregory P. Smith2024-11-201-8/+64
| | | | | | | | | | | | | | | | | | | This adds authentication to the forkserver control socket. In the past only filesystem permissions protected this socket from code injection into the forkserver process by limiting access to the same UID, which didn't exist when Linux abstract namespace sockets were used (see issue) meaning that any process in the same system network namespace could inject code. We've since stopped using abstract namespace sockets by default, but protecting our control sockets regardless of type is a good idea. This reuses the HMAC based shared key auth already used by `multiprocessing.connection` sockets for other purposes. Doing this is useful so that filesystem permissions are not relied upon and trust isn't implied by default between all processes running as the same UID with access to the unix socket. ### pyperformance benchmarks No significant changes. Including `concurrent_imap` which exercises `multiprocessing.Pool.imap` in that suite. ### Microbenchmarks This does _slightly_ slow down forkserver use. How much so appears to depend on the platform. Modern platforms and simple platforms are less impacted. This PR adds additional IPC round trips to the control socket to tell forkserver to spawn a new process. Systems with potentially high latency IPC are naturally impacted more. Typically a 1-4% slowdown on a very targeted process creation microbenchmark, with a worst case overloaded system slowdown of 20%. No evidence that these slowdowns appear in practical sense. See the PR for details.
* gh-117378: Fix multiprocessing forkserver preload sys.path inheritance. ↵Gregory P. Smith2024-11-091-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-126538) gh-117378: Fix multiprocessing forkserver preload sys.path inheritance. `sys.path` was not properly being sent from the parent process when launching the multiprocessing forkserver process to preload imports. This bug has been there since the forkserver start method was introduced in Python 3.4. It was always _supposed_ to inherit `sys.path` the same way the spawn method does. Observable behavior change: A `''` value in `sys.path` will now be replaced in the forkserver's `sys.path` with an absolute pathname `os.path.abspath(os.getcwd())` saved at the time that `multiprocessing` was imported in the parent process as it already was when using the spawn start method. **This will only be observable during forkserver preload imports**. The code invoked before calling things in another process already correctly sets `sys.path`. Which is likely why this went unnoticed for so long as a mere performance issue in some configurations. A workaround for the bug on impacted Pythons is to set PYTHONPATH in the environment before multiprocessing's forkserver process was started. Not perfect as that is then inherited by other children, etc, but likely good enough for many people's purposes. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-83856: Honor atexit for all multiprocessing start methods (GH-114279)Tian Gao2024-05-031-0/+4
| | | | | Use atexit for all multiprocessing start methods to cleanup. See the GH-114279 PR discussion and related issue for details as to why.
* gh-107963: Fix set_forkserver_preload to check the type of given list (#107965)Dong-hee Na2023-08-151-1/+1
| | | | gh-107963: Fix set_forkserver_preload to check the type of given list
* bpo-40094: Add os.waitstatus_to_exitcode() (GH-19201)Victor Stinner2020-04-011-8/+2
| | | | | | | | | | | | | | Add os.waitstatus_to_exitcode() function to convert a wait status to an exitcode. Suggest waitstatus_to_exitcode() usage in the documentation when appropriate. Use waitstatus_to_exitcode() in: * multiprocessing, os, subprocess and _bootsubprocess modules; * test.support.wait_process(); * setup.py: run_command(); * and many tests.
* bpo-39850: Add support for abstract sockets in multiprocessing (GH-18866)Pablo Galindo2020-03-091-2/+4
|
* bpo-37421: multiprocessing tests now stop ForkServer (GH-14601)Victor Stinner2019-07-051-0/+19
| | | | | multiprocessing tests now stop the ForkServer instance if it's running: close the "alive" file descriptor to ask the server to stop and then remove its UNIX address.
* bpo-36888: Add multiprocessing.parent_process() (GH-13247)Thomas Moreau2019-05-201-1/+2
|
* bpo-36867: Make semaphore_tracker track other system resources (GH-13222)Pierre Glaser2019-05-101-4/+4
| | | The multiprocessing.resource_tracker replaces the multiprocessing.semaphore_tracker module. Other than semaphores, resource_tracker also tracks shared_memory segments. Patch by Pierre Glaser.
* bpo-31308: If multiprocessing's forkserver dies, launch it again when ↵Antoine Pitrou2017-11-031-5/+16
| | | | | | | | | | | | | | | | | | | | | | necessary (#3246) * bpo-31308: If multiprocessing's forkserver dies, launch it again when necessary. * Fix test on Windows * Add NEWS entry * Adopt a different approach: ignore SIGINT and SIGTERM, as in semaphore tracker. * Fix comment * Make sure the test doesn't muck with process state * Also test previously-started processes * Update 2017-08-30-17-59-36.bpo-31308.KbexyC.rst * Avoid masking SIGTERM in forkserver. It's not necessary and causes a race condition in test_many_processes.
* bpo-5001: More-informative multiprocessing error messages (#3079)Allen W. Smith, Ph.D2017-08-291-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Make error message more informative Replace assertions in error-reporting code with more-informative version that doesn't cause confusion over where and what the error is. * Additional clarification + get travis to check * Change from SystemError to TypeError As suggested in PR comment by @pitrou, changing from SystemError; TypeError appears appropriate. * NEWS file installation; ACKS addition (will do my best to justify it by additional work) * Making current AssertionErrors in multiprocessing more informative * Blurb added re multiprocessing managers.py, queues.py cleanup * Further multiprocessing cleanup - went through pool.py * Fix two asserts in multiprocessing/util.py * Most asserts in multiprocessing more informative * Didn't save right version * Further work on multiprocessing error messages * Correct typo * Correct typo v2 * Blasted colon... serves me right for trying to work on two things at once * Simplify NEWS entry * Update 2017-08-18-17-16-38.bpo-5001.gwnthq.rst * Update 2017-08-18-17-16-38.bpo-5001.gwnthq.rst OK, never mind. * Corrected (thanks to pitrou) error messages for notify * Remove extraneous backslash in docstring.
* bpo-26732: fix too many fds in processes started with the "forkserver" ↵Antoine Pitrou2017-07-221-1/+4
| | | | | | | | | | method (#2813) * bpo-26732: fix too many fds in processes started with the "forkserver" method A child process would inherit as many fds as the number of still-running children. * Add blurb and test comment
* Fix bpo-30596: Add close() method to multiprocessing.Process (#2010)Antoine Pitrou2017-06-241-4/+12
| | | | | | | | | | * Fix bpo-30596: Add close() method to multiprocessing.Process * Raise ValueError if close() is called before the Process is finished running * Add docs * Add NEWS blurb
* bpo-30643: Fix race condition in signal wakeup in forkserver (followup to PR ↵Antoine Pitrou2017-06-131-4/+8
| | | | | | | | | | | | | #1989) (#2139) * Fix race condition in signal wakeup in forkserver (followup to PR #1989) There's an admittedly well-known race condition where ECHILD can arrive just before the C function epoll_wait() and the latter wouldn't therefore return EINTR. The solution is to use set_wakeup_fd(), which was designed to avoid such race conditions. * Reset wakeup fd in child
* Fix bpo-30589: improve Process.exitcode with forkserver (#1989)Antoine Pitrou2017-06-121-35/+86
| | | | | | | | * Fix bpo-30589: improve Process.exitcode with forkserver When the child is killed, Process.exitcode should return -signum, not 255. * Add Misc/NEWS
* bpo-16500: Allow registering at-fork handlers (#1715)Antoine Pitrou2017-05-271-5/+0
| | | | | | | | | | | | * bpo-16500: Allow registering at-fork handlers * Address Serhiy's comments * Add doc for new C API * Add doc for new Python-facing function * Add NEWS entry + doc nit
* bpo-30296 Remove unnecessary tuples, lists, sets, and dicts (#1489)Jon Dufresne2017-05-181-2/+1
| | | | | | | | * Replaced list(<generator expression>) with list comprehension * Replaced dict(<generator expression>) with dict comprehension * Replaced set(<list literal>) with set literal * Replaced builtin func(<list comprehension>) with func(<generator expression>) when supported (e.g. any(), all(), tuple(), min(), & max())
* bpo-30185: avoid KeyboardInterrupt tracebacks in forkserver (#1319)Antoine Pitrou2017-05-041-6/+14
| | | | | | * bpo-30185: avoid KeyboardInterrupt tracebacks in forkserver * Tweak comment
* Issue #28053: Applying refactorings, docs and other cleanup to follow.Davin Potts2016-09-091-1/+1
|
* Issue #25654:Victor Stinner2016-03-251-7/+1
| | | | | | | | | * multiprocessing: open file with closefd=False to avoid ResourceWarning * _test_multiprocessing: open file with O_EXCL to detect bugs in tests (if a previous test forgot to remove TESTFN) * test_sys_exit(): remove TESTFN after each loop iteration Initial patch written by Serhiy Storchaka.
* Issue #23285: PEP 475 -- Retry system calls failing with EINTR.Charles-François Natali2015-02-071-16/+2
|
* Issue #21566: Make use of socket.listen() default backlog.Charles-François Natali2014-07-231-1/+1
|
* Issue #18999: Make multiprocessing use context objects.Richard Oudkerk2013-10-161-101/+113
| | | | | This allows different parts of a program to use different methods for starting processes without interfering with each other.
* Issue #18934: multiprocessing: use selectors module.Charles-François Natali2013-09-051-4/+10
|
* Issue #18865: PEP 446 makes multiprocessing.util.pipe() unnecessary.Richard Oudkerk2013-08-281-1/+1
|
* Issue #18571: Implementation of the PEP 446: file descriptors and file handlesVictor Stinner2013-08-271-2/+2
| | | | | are now created non-inheritable; add functions os.get/set_inheritable(), os.get/set_handle_inheritable() and socket.socket.get/set_inheritable().
* Stop making fork server have copy of semaphore_tracker_fd.Richard Oudkerk2013-08-221-6/+7
|
* Issue #18762: Fix EBADF error when using forkserver.Richard Oudkerk2013-08-221-30/+25
|
* Issue #18762: Print debug info on failure to create new forkserver process.Richard Oudkerk2013-08-211-0/+15
| | | | Also modify test code to hopefully avoid deadlock on failure.
* Issue #8713: Support alternative start methods in multiprocessing on Unix.Richard Oudkerk2013-08-141-0/+238
See http://hg.python.org/sandbox/sbt#spawn