trio icon indicating copy to clipboard operation
trio copied to clipboard

Python 3.15: DeprecationWarning about fork+threads in test_clear_thread_cache_after_fork

Open musicinmybrain opened this issue 2 months ago • 2 comments

In early Fedora integration work with development versions of Python 3.15, we found that test_clear_thread_cache_after_fork fails with the following DeprecationWarning:

=================================== FAILURES ===================================
______________________ test_clear_thread_cache_after_fork ______________________

    @pytest.mark.skipif(not hasattr(os, "fork"), reason="os.fork isn't supported")
    def test_clear_thread_cache_after_fork() -> None:
        assert hasattr(os, "fork")
    
        def foo() -> None:
            pass
    
        # ensure the thread cache exists
        done = threading.Event()
        start_thread_soon(foo, lambda _: done.set())
        done.wait()
    
>       child_pid = os.fork()
E       DeprecationWarning: This process (pid=1741) is multi-threaded, use of fork() may lead to deadlocks in the child.

../BUILDROOT/usr/lib/python3.15/site-packages/trio/_core/_tests/test_thread_cache.py:213: DeprecationWarning
=========================== short test summary info ============================
FAILED _core/_tests/test_thread_cache.py::test_clear_thread_cache_after_fork
====== 1 failed, 695 passed, 85 skipped, 8 deselected, 3 xfailed in 6.34s ======

musicinmybrain avatar Nov 13 '25 13:11 musicinmybrain

Pretty sure we should just suppress that with a conditional with pytest.warns. We'd ideally also start testing 3.15 in CI ourselves to get it covered.

jakkdl avatar Nov 13 '25 19:11 jakkdl

This is actually a bit strange because I remember hitting this in 3.12: https://github.com/python-trio/trio/issues/2764#issuecomment-2635785862

How'd I manage to make this test work on 3.12 but not 3.15 if both have this warning...

A5rocks avatar Nov 25 '25 15:11 A5rocks