Commit Graph

223 Commits

Author SHA1 Message Date
Miss Islington (bot) dfedbdba40
[3.13] gh-120012: clarify the behaviour of `multiprocessing.Queue.empty` on closed queues. (GH-120102) (#120469)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2024-07-14 04:24:58 -06:00
Miss Islington (bot) 1dc7fcd803
[3.13] gh-119064: Use os_helper.FakePath instead of pathlib.Path in tests (GH-119065) (GH-119087)
(cherry picked from commit 0152dc4ff5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-05-16 10:51:18 +03:00
Tian Gao 998c3856c1
gh-83856: Honor atexit for all multiprocessing start methods (GH-114279)
Use atexit for all multiprocessing start methods to cleanup.
See the GH-114279 PR discussion and related issue for details as to why.
2024-05-03 11:45:46 -07:00
Sam Gross 83c51da6ce
gh-118413: Fix test_release_task_refs on free-threaded build (#118494)
The `time.sleep()` call should happen before the GC to give the worker
threads time to clean-up their remaining references to objs.
Additionally, use `support.gc_collect()` instead of `gc.collect()`
just in case the extra GC calls matter.
2024-05-02 13:41:15 -04:00
Sam Gross c408c36e9b
gh-118413: Temporarily skip `test_release_task_refs` in free-threaded builds (#118491) 2024-05-01 17:58:22 -04:00
Malcolm Smith 1d3225ae05
gh-116622: Test updates for Android (#117299)
- re-enable test_fcntl_64_bit on Linux aarch64, but disable it on all
  Android ABIs
- use support.setswitchinterval in all relevant tests
- skip test_fma_zero_result on Android x86_64
- accept EACCES when calling os.get_terminal_size on Android
2024-04-05 20:57:36 +00:00
Gregory P. Smith ea1803e608
gh-88118: Fix some test_multiprocessing flakiness. (#116434)
Fix some test_multiprocessing flakiness.

Potentially introduced by https://github.com/python/cpython/pull/25845

not joining that thread likely leads to recently observed "environment
changed" logically passing but overall failing tests seen on some
buildbots similar to:

```
1 test altered the execution environment (env changed):
    test.test_multiprocessing_fork.test_processes

2 re-run tests:
    test.test_multiprocessing_fork.test_processes
    test.test_multiprocessing_forkserver.test_processes
```
2024-03-06 13:39:06 -08:00
Miguel Brito 686ec17f50
bpo-43952: Fix multiprocessing Listener authkey bug (GH-25845)
Listener.accept() no longer hangs when authkey is an empty bytes object.
2024-02-27 14:57:59 +00:00
Serhiy Storchaka 79811ededd
gh-115886: Handle embedded null characters in shared memory name (GH-115887)
shm_open() and shm_unlink() now check for embedded null characters in
the name and raise an error instead of silently truncating it.
2024-02-25 11:31:03 +02:00
Petr Viktorin 4a9e6497c2
gh-104090: Add exit code to multiprocessing ResourceTracker (GH-115410)
This builds on https://github.com/python/cpython/pull/106807, which adds
a return code to ResourceTracker, to make future debugging easier.
Testing this “in situ” proved difficult, since the global ResourceTracker is
involved in test infrastructure. So, the tests here create a new instance and
feed it fake data.

---------

Co-authored-by: Yonatan Bitton <yonatan.bitton@perception-point.io>
Co-authored-by: Yonatan Bitton <bityob@gmail.com>
Co-authored-by: Antoine Pitrou <antoine@python.org>
2024-02-21 13:54:57 +01:00
Steve Dower ea25f32d5f
gh-89240: Enable multiprocessing on Windows to use large process pools (GH-107873)
We add _winapi.BatchedWaitForMultipleObjects to wait for larger numbers of handles.
This is an internal module, hence undocumented, and should be used with caution.
Check the docstring for info before using BatchedWaitForMultipleObjects.
2024-02-13 00:28:35 +00:00
Serhiy Storchaka ce75b4c26d
gh-113205: test_multiprocessing.test_terminate: Give tasks a chance to start (GH-114249) 2024-01-24 09:13:09 +02:00
Petr Viktorin c1db960608
gh-113205: test_multiprocessing.test_terminate: Test the API on threadpools (#114186)
gh-113205: test_multiprocessing.test_terminate: Test the API works on threadpools

Threads can't be forced to terminate (without potentially corrupting too much
state), so the  expected behaviour of `ThreadPool.terminate` is to wait for
the currently executing tasks to finish.

The entire test was skipped in GH-110848 (0e9c364f4a).
Instead of skipping it entirely, we should ensure the API eventually succeeds:
use a shorter timeout.

For the record: on my machine, when the test is un-skipped, the task manages to
start in about 1.5% cases.
2024-01-17 17:15:29 -08:00
Xu Song ce77ee5035
gh-113421: Fix multiprocessing logger for "%(filename)s" (GH-113423) 2023-12-24 12:04:12 +02:00
pan324 81ee026091
gh-82300: Add track parameter to multiprocessing.shared_memory (#110778)
Add a track parameter to shared memory to allow resource tracking via the side-launched resource tracker process to be disabled on platforms that use it (POSIX).

This allows people who do not want automated cleanup at process exit because they are using the shared memory with processes not participating in Python's resource tracking to use the shared_memory API.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-12-05 00:11:44 -08:00
Antoine Pitrou 0e9c364f4a
GH-110829: Ensure Thread.join() joins the OS thread (#110848)
Joining a thread now ensures the underlying OS thread has exited. This is required for safer fork() in multi-threaded processes.

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2023-11-04 13:59:24 +00:00
Serhiy Storchaka 624ace5a2f
gh-111284: Make multiprocessing tests with threads faster and more reliable (GH-111285) 2023-10-30 19:18:36 +02:00
Victor Stinner 790ecf6302
gh-110662: multiprocessing test_async_timeout() increase timeout (#110663)
Increase timeout from 1 second to 30 seconds, if not longer. The
important part is that apply_async() takes longer than TIMEOUT2.
2023-10-11 02:36:06 +00:00
Victor Stinner 1556f426da
gh-110666: Fix multiprocessing test_terminate() elapsed (#110667)
multiprocessing test_terminate() and test_wait_socket_slow() no
longer test the CI performance: no longer check maximum elapsed time.

Add CLOCK_RES constant: tolerate a difference of 100 ms.
2023-10-11 01:49:09 +00:00
Victor Stinner f901f56313
gh-110656: Fix logging test_post_fork_child_no_deadlock() if ASAN (#110657)
Skip test_post_fork_child_no_deadlock() if Python is built with ASAN.

Add support.HAVE_ASAN_FORK_BUG.
2023-10-11 02:57:53 +02:00
Victor Stinner 5eae8dc2cb
gh-109840: Fix multiprocessing test_waitfor_timeout() (#110428)
Don't measure the CI performance: don't fail if cond.wait_for() takes
longer than 1 second on a slow CI.
2023-10-05 19:32:06 +00:00
Victor Stinner bd4518c60c
gh-110036: multiprocessing Popen.terminate() catches PermissionError (#110037)
On Windows, multiprocessing Popen.terminate() now catchs
PermissionError and get the process exit code. If the process is
still running, raise again the PermissionError. Otherwise, the
process terminated as expected: store its exit code.
2023-09-29 02:41:12 +02:00
Victor Stinner bc06743533
gh-89363: Skip threading test_is_alive_after_fork() if ASAN (#109835)
Skip test_is_alive_after_fork() of test_threading if Python is built
with Address Sanitizer (ASAN).
2023-09-25 16:02:04 +00:00
Victor Stinner b03a791497
gh-109706: Fix multiprocessing test_nested_startmethod() (#109707)
Don't check order, queue items can be written in any order.
2023-09-22 23:49:32 +02:00
Serhiy Storchaka 1e0d62793a
gh-108416: Mark slow but not CPU bound test methods with requires_resource('walltime') (GH-108480) 2023-09-05 17:56:30 +03:00
Serhiy Storchaka f3ba0a74cd
gh-108416: Mark slow test methods with @requires_resource('cpu') (GH-108421)
Only mark tests which spend significant system or user time,
by itself or in subprocesses.
2023-09-02 07:45:34 +03:00
albanD add8d45cbe
gh-108520: Fix bad fork detection in nested multiprocessing use case (#108568)
gh-107275 introduced a regression where a SemLock would fail being passed along nested child processes, as the `is_fork_ctx` attribute would be left missing after the first deserialization.

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
2023-08-30 17:07:41 +00:00
Victor Stinner aa9a359ca2
gh-108388: Split test_multiprocessing_spawn (#108396)
Split test_multiprocessing_fork, test_multiprocessing_forkserver and
test_multiprocessing_spawn into test packages. Each package is made
of 4 sub-tests: processes, threads, manager and misc. It allows
running more tests in parallel and so reduce the total test duration.
2023-08-24 05:35:39 +02:00
albanD 1700d34d31
gh-77377: Ensure multiprocessing SemLock is valid for spawn-based Process before serializing it (#107275)
Ensure multiprocessing SemLock is valid for spawn Process before serializing it.

Creating a multiprocessing SemLock with a fork context, and then trying to pass it to a spawn-created Process, would segfault if not detected early.

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
2023-08-23 20:27:35 +00:00
Dong-hee Na 6515ec3d3d
gh-107963: Fix set_forkserver_preload to check the type of given list (#107965)
gh-107963: Fix set_forkserver_preload to check the type of given list
2023-08-15 15:58:12 +02:00
Andrew Geng 5f7d4ecf30
gh-106558: break ref cycles through exceptions in multiprocessing manager (#106559) 2023-08-11 17:44:18 +00:00
Gregory P. Smith c60df361ce
gh-90876: Restore the ability to import multiprocessing when `sys.executable` is `None` (#106464)
Prevent `multiprocessing.spawn` from failing to *import* in environments
where `sys.executable` is `None`.  This regressed in 3.11 with the addition
of support for path-like objects in multiprocessing.

Adds a test decorator to have tests only run when part of test_multiprocessing_spawn to `_test_multiprocessing.py` so we can start to avoid re-running the same not-global-state specific test in all 3 modes when there is no need.
2023-07-06 22:46:50 +00:00
Victor Stinner ae319e4b43
gh-105407: Remove unused imports in tests (#105408) 2023-06-06 22:50:43 +02:00
Christian Heimes 3ed57e4995
gh-61460: Stronger HMAC in multiprocessing (#20380)
bpo-17258:  `multiprocessing` now supports stronger HMAC algorithms for inter-process connection authentication rather than only HMAC-MD5.

Signed-off-by: Christian Heimes <christian@python.org>

gpshead: I Reworked to be more robust while keeping the idea.

The protocol modification idea remains, but we now take advantage of the
message length as an indicator of legacy vs modern protocol version.  No
more regular expression usage.  We now default to HMAC-SHA256, but do so
in a way that will be compatible when communicating with older clients
or older servers. No protocol transition period is needed.

More integration tests to verify these claims remain true are required. I'm
unaware of anyone depending on multiprocessing connections between
different Python versions.

---------

Signed-off-by: Christian Heimes <christian@python.org>
Co-authored-by: Gregory P. Smith [Google] <greg@krypto.org>
2023-05-20 23:33:09 +00:00
Gregory P. Smith d4c410f0f9
gh-84559: Remove the new multiprocessing warning, too disruptive. (#101551)
This reverts the core of #100618 while leaving relevant documentation
improvements and minor refactorings in place.
2023-02-03 15:20:46 -08:00
Gregory P. Smith 0ca67e6313
GH-84559: Deprecate fork being the multiprocessing default. (#100618)
This starts the process. Users who don't specify their own start method
and use the default on platforms where it is 'fork' will see a
DeprecationWarning upon multiprocessing.Pool() construction or upon
multiprocessing.Process.start() or concurrent.futures.ProcessPool use.

See the related issue and documentation within this change for details.
2023-02-02 15:50:35 -08:00
Serhiy Storchaka 76f43fc09a
gh-60203: Always pass True/False as boolean arguments in tests (GH-99983)
Unless we explicitly test non-bool values.
2022-12-04 14:28:56 +02:00
Jack Hindmarch a3be874334
gh-92886: Fix tests that fail when running with optimizations (`-O`) in `_test_multiprocessing.py` (GH-93233) 2022-10-19 11:07:07 +01:00
Koki Saito 19ca114645
gh-96819: multiprocessing.resource_tracker: check if length of pipe write <= 512 (#96890)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2022-10-02 17:41:01 -07:00
Koki Saito 14d4f68ebb
gh-97706: multiprocessing tests: Delete unused variable `rand` (#97707) 2022-10-02 17:37:36 -07:00
Christian Heimes 5956de16cd
gh-95212: make multiprocessing test case parallel-safe (GH-95213) 2022-07-25 06:44:40 +02:00
Kumar Aditya cfafd3adf8
GH-94736: mark SemLock test as linux only (GH-94750)
See https://buildbot.python.org/all/#/builders/172/builds/2522
The PR skips the test on non-linux platforms.

Automerge-Triggered-By: GH:pablogsal
2022-07-11 07:35:47 -07:00
Kumar Aditya f5b76330cf
GH-94736: Fix _multiprocessing.SemLock subclassing (#94738)
* fix allocator and deallocator

* 📜🤖 Added by blurb_it.

* code review

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2022-07-11 13:12:36 +01:00
Irit Katriel e37a158725
GH-83658: make multiprocessing.Pool raise an exception if maxtasksperchild is not None or a positive int (GH-93364)
Closes #83658.
2022-06-17 00:14:26 -07:00
Victor Stinner 50e0866f87
Tests call sleeping_retry() with SHORT_TIMEOUT (#93870)
Tests now call busy_retry() and sleeping_retry() with SHORT_TIMEOUT
or LONG_TIMEOUT (of test.support), rather than hardcoded constants.

Add also WAIT_ACTIVE_CHILDREN_TIMEOUT constant to
_test_multiprocessing.
2022-06-15 18:49:14 +02:00
Victor Stinner 7e9eaad864
Add test.support.busy_retry() (#93770)
Add busy_retry() and sleeping_retry() functions to test.support.
2022-06-15 11:42:10 +02:00
Leo Trol 30610d2837
gh-90549: Fix leak of global named resources using multiprocessing spawn (#30617)
Co-authored-by: XD Trol <milestonejxd@gmail.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
2022-06-09 18:55:12 +02:00
Géry Ogam 5576ddbbbc
bpo-46720: Add support for path-like objects to multiprocessing.set_executable for Windows (GH-31279)
This bring the API to be on a par with Unix-like systems.
2022-04-22 15:47:09 -07:00
Victor Stinner 061a8bf77c
gh-91231: Add shutdown_timeout to multiprocessing BaseManager (#32112)
Add an optional keyword 'shutdown_timeout' parameter to the
multiprocessing.BaseManager constructor. Kill the process if
terminate() takes longer than the timeout.

Multiprocessing tests pass test.support.SHORT_TIMEOUT
to BaseManager.shutdown_timeout.
2022-04-19 16:27:00 +02:00
Victor Stinner 9204bb72a2
bpo-46633: Skip tests on ASAN and/or MSAN builds (GH-31632)
Skip tests on ASAN and/or MSAN builds:

* multiprocessing tests
* test___all__
* test_concurrent_futures
* test_decimal
* test_peg_generator
* test_tools

The ASAN job of GitHub Actions no longer excludes these tests.
2022-03-01 15:44:08 +01:00