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

test_async_timeout makes multiprocessing tests with threads slow #111284

Closed
serhiy-storchaka opened this issue Oct 24, 2023 · 0 comments
Closed
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes tests Tests in the Lib/test dir topic-multiprocessing

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Oct 24, 2023

I noticed an interesting effect. When run all tests in test.test_multiprocessing_spawn.test_threads, progress lingers (on 30 almost seconds) on test_terminate. But when run only test_terminate, it completes quickly. Further research revealed that it is only slow after test_async_timeout. If run test_async_timeout only, it completes quickly, but then Python freezes on 30 seconds (in tearDownClass).

It is because test_async_timeout runs a long task in a thread, and then either test_terminate or tearDownClass need to wait until it is finished. This slow task can also affect all other tests, because it monopolizes one worker.

The solution is to use a new pool for test_async_timeout and terminate it immediately after testing. It does not help for threads, but in that case we can unblock the slow task using Event.

There is other issue with test_terminate: it terminates the pool that is global for the class, so no other tests that uses the pool can be run after it. It only worked because test_terminate was at the end of sorted methods list. The solution is to use new pool in test_terminate.

It saves 1.5 minutes and makes tests more robust.

Linked PRs

@serhiy-storchaka serhiy-storchaka added tests Tests in the Lib/test dir 3.11 only security fixes 3.12 bugs and security fixes topic-multiprocessing 3.13 bugs and security fixes labels Oct 24, 2023
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Oct 24, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 30, 2023
…ore reliable (pythonGH-111285)

(cherry picked from commit 624ace5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 30, 2023
…ore reliable (pythonGH-111285)

(cherry picked from commit 624ace5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Oct 30, 2023
…more reliable (GH-111285) (GH-111511)

(cherry picked from commit 624ace5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Oct 30, 2023
…more reliable (GH-111285) (GH-111510)

(cherry picked from commit 624ace5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
FullteaR pushed a commit to FullteaR/cpython that referenced this issue Nov 3, 2023
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes tests Tests in the Lib/test dir topic-multiprocessing
Projects
None yet
Development

No branches or pull requests

1 participant