Skip to content

Conversation

@pareshjoshij
Copy link
Contributor

The test_printoptions_thread_safety function spawns two threading.Thread objects but never calls .join() on them.

This causes multiple problems:

  • The test function can return and be marked as "passed" by pytest before the assertions inside the threads have executed → intermittent failures or false positives.
  • Threads are left running when the test process exits → thread leakage, occasional segmentation faults, and “daemon thread still running” warnings.
  • Unnecessary non-determinism in an otherwise stable thread-safety regression test.

All other threading tests in the same file already join their threads properly (via run_threaded or ThreadPoolExecutor).

Fix
Add the two missing lines:

    task1.start()
    task2.start()
    task1.join()
    task2.join()

The test_printoptions_thread_safety function spawned threads but exited
immediately without joining them. This created a race condition where:
1. The test could return 'Passed' before the assertions inside the threads actually ran.
2. "Zombie" threads were left running in the background, potentially interfering with subsequent tests.

Added .join() calls for both threads to ensure proper execution and teardown.
@jorenham jorenham changed the title TEST: Join threads in test_printoptions_thread_safety TST: Join threads in test_printoptions_thread_safety Nov 20, 2025
@jorenham jorenham added the 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) label Nov 20, 2025
@ngoldbaum
Copy link
Member

Thanks! I re-triggered the failing test runs, the failures should be unrelated.

This is one reason I want to republish the threading_helper from CPython's test module: https://docs.python.org/3/library/test.html#module-test.support.threading_helper. Alas it's hard to find the time for projects like that...

@ngoldbaum ngoldbaum added this to the 2.4.0 release milestone Nov 21, 2025
@seberg
Copy link
Member

seberg commented Nov 21, 2025

Makes sense, thanks @pareshjoshij and Nathan.

@seberg seberg merged commit dd80e20 into numpy:main Nov 21, 2025
87 of 89 checks passed
@pareshjoshij
Copy link
Contributor Author

Thanks a lot @ngoldbaum sir & @seberg sir for reviewing and merging! 🎉
Feels great to have my first NumPy contribution accepted. Can’t wait to work on more issues

@pareshjoshij pareshjoshij deleted the test-join-printoptions-threads branch November 22, 2025 03:56
cakedev0 pushed a commit to cakedev0/numpy that referenced this pull request Dec 5, 2025
The test_printoptions_thread_safety function spawned threads but exited
immediately without joining them. This created a race condition where:
1. The test could return 'Passed' before the assertions inside the threads actually ran.
2. "Zombie" threads were left running in the background, potentially interfering with subsequent tests.

Added .join() calls for both threads to ensure proper execution and teardown.
IndifferentArea pushed a commit to IndifferentArea/numpy that referenced this pull request Dec 7, 2025
The test_printoptions_thread_safety function spawned threads but exited
immediately without joining them. This created a race condition where:
1. The test could return 'Passed' before the assertions inside the threads actually ran.
2. "Zombie" threads were left running in the background, potentially interfering with subsequent tests.

Added .join() calls for both threads to ensure proper execution and teardown.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

05 - Testing 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants