Skip to content

Conversation

b-pass
Copy link
Contributor

@b-pass b-pass commented Jul 24, 2025

The test was throwing import errors past the lifetime of the owning scoped_interpreter

Description

The test was supposed to import a test module, but because it is "isolated", the path is not set, so the module cannot be imported. A ModuleNotFound error is thrown, but not caught, and then propagates past the scoped_interpreter which owns it.

The stack of the SEGV doesn't point to the test itself, so it was difficult to track down:

#0  0x0000000004b6fec9 in new_threadstate (interp=0x0) at ../Python/pystate.c:1388
#1  0x0000000004b726ad in PyGILState_Ensure () at ../Python/pystate.c:2218
#2  0x0000000000162821 in pybind11::gil_scoped_acquire_simple::gil_scoped_acquire_simple (this=0x1ffeffeb8c)
    at /home/user/pybind11/include/pybind11/gil_simple.h:17
#3  0x0000000000163cc8 in pybind11::error_already_set::what (this=0x6f58d60) at /home/user/pybind11/include/pybind11/pybind11.h:3345
#4  0x000000000012dd32 in Catch::ExceptionTranslatorRegistry::translateActiveException[abi:cxx11]() const (this=0x5729138)
    at /home/user/pybind11/build12/tests/catch/catch.hpp:10720
#5  0x00000000001343ca in Catch::translateActiveException[abi:cxx11]() () at /home/user/pybind11/build12/tests/catch/catch.hpp:12523
#6  0x00000000001369e0 in Catch::RunContext::runCurrentTest (this=0x1ffefff1f0, redirectedCout="", redirectedCerr="")
    at /home/user/pybind11/build12/tests/catch/catch.hpp:13008
#7  0x0000000000135236 in Catch::RunContext::runTest (this=0x1ffefff1f0, testCase=...) at /home/user/pybind11/build12/tests/catch/catch.hpp:12759
#8  0x0000000000138533 in Catch::(anonymous namespace)::TestGroup::execute (this=0x1ffefff1e0) at /home/user/pybind11/build12/tests/catch/catch.hpp:13352
#9  0x0000000000139abb in Catch::Session::runInternal (this=0x1ffefff510) at /home/user/pybind11/build12/tests/catch/catch.hpp:13562
#10 0x000000000013978e in Catch::Session::run (this=0x1ffefff510) at /home/user/pybind11/build12/tests/catch/catch.hpp:13518
#11 0x00000000001841af in Catch::Session::run<char> (this=0x1ffefff510, argc=2, argv=0x1ffefff7e8) at /home/user/pybind11/build12/tests/catch/catch.hpp:13236
#12 0x00000000001521bb in main (argc=2, argv=0x1ffefff7e8) at /home/user/pybind11/tests/test_embed/catch.cpp:40

I do not really understand how this passes as it is.

@rwgk this is what I found when investigating the flake from #5766. I don't know if this is the actual cause....

Suggested changelog entry:

  • fix an IsolatedConfig test

b-pass added 3 commits July 24, 2025 17:58
The test was throwing import errors past the lifetime of the owning scoped_interpreter
@rwgk
Copy link
Collaborator

rwgk commented Jul 27, 2025

@b-pass There was this flake again (resolved by a rerun):

https://github.com/pybind/pybind11/actions/runs/16509608392/job/46688698596?pr=5768

D:/a/_temp/msys64/mingw64/bin/mingw32-make.exe  -f tests\test_embed\CMakeFiles\cpptest.dir\build.make tests/test_embed/CMakeFiles/cpptest.dir/depend
mingw32-make[3]: Entering directory 'D:/a/pybind11/pybind11/build2'
D:\a\_temp\msys64\mingw64\bin\cmake.exe -E cmake_depends "MinGW Makefiles" D:\a\pybind11\pybind11 D:\a\pybind11\pybind11\tests\test_embed D:\a\pybind11\pybind11\build2 D:\a\pybind11\pybind11\build2\tests\test_embed D:\a\pybind11\pybind11\build2\tests\test_embed\CMakeFiles\cpptest.dir\DependInfo.cmake "--color="
mingw32-make[3]: Leaving directory 'D:/a/pybind11/pybind11/build2'
D:/a/_temp/msys64/mingw64/bin/mingw32-make.exe  -f tests\test_embed\CMakeFiles\cpptest.dir\build.make tests/test_embed/CMakeFiles/cpptest.dir/build
mingw32-make[3]: Entering directory 'D:/a/pybind11/pybind11/build2'
cd /d D:\a\pybind11\pybind11\build2\tests\test_embed && D:\a\pybind11\pybind11\build2\tests\test_embed\test_embed.exe
Exception ignored in: <module 'threading' from 'D:/a/_temp/msys64/mingw64/lib/python3.12/threading.py'>
Traceback (most recent call last):
  File "D:/a/_temp/msys64/mingw64/lib/python3.12/threading.py", line 1602, in _shutdown
    assert tlock.locked()
           ^^^^^^^^^^^^^^
AssertionError: 
Windows fatal exception: access violation

For context, from a little further up in the log:

============================= test session starts =============================
platform win32 -- Python 3.12.11, pytest-8.4.0, pluggy-1.6.0
installed packages of interest: numpy==2.3.1 scipy==1.15.3
C++ Info: 15.1.0 C++14 __pybind11_internals_v11_mingw_libstdcpp_gxx_abi_1xxx_use_cxx11_abi_1__ PYBIND11_SIMPLE_GIL_MANAGEMENT=False

I.e. similar to what I saw (and reported elsewhere) before, this is with Python 3.12.

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

@rwgk rwgk merged commit 33533ff into pybind:master Jul 27, 2025
145 of 146 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jul 27, 2025
@henryiii henryiii changed the title Fix IsolatedConfig test tests: fix IsolatedConfig test Aug 21, 2025
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants