[BUG] 🐍 3.9 Windows: Crash in init in debug build
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Issue description
In a minimal build (a minimized cmake_example) all works as expected in release mode. In debug build though an assertion is raised during module initialization in PyGILState_Ensure, called from PyInit_cmake_example.
Reproducible example code
The attached minimal example fails to run with an assertion in debug mode, but runs in release:
test_pybind11.zip
Build & test steps with cwd in extracted example:
cd testmod
git clone https://github.com/pybind/pybind11.git
cd ..
mkdir build
cd build
cmake ../testmod
cmake --build . --config Debug
cd ..
python test.py
Assertion call stack in debug mode on module import (as in Python 3.9.2):
...
python39_d.dll!PyGILState_Ensure() Line 1357 (c:\Python\Python\pystate.c:1357)
cmake_example.cp39-win_amd64.pyd!`pybind11::detail::get_internals'::`2'::gil_scoped_acquire_local::gil_scoped_acquire_local() Line 264 (<path>\testmod\pybind11\include\pybind11\detail\internals.h:264)
cmake_example.cp39-win_amd64.pyd!pybind11::detail::get_internals() Line 267 (<path>\testmod\pybind11\include\pybind11\detail\internals.h:267)
cmake_example.cp39-win_amd64.pyd!PyInit_cmake_example() Line 9 (<path>\mod.cpp:9)
python39.dll!_PyImport_LoadDynamicModuleWithSpec(_object * spec, _iobuf *) Line 165 (c:\Python\Python\importdl.c:165)
...
Versions:
pybind11 c58758d04915197e16c7c0d8efc3b85c63b765f9 and 9c0aa69937dbb9d7023123d5d98914855432982c,
Python 3.8.8 and Python 3.9.2.
CMake 3.19.6
MSVC++2019 (19.28.29336.0)
Same project works on Ubuntu 20.04 with default package versions and Python "3.9.0+".
Also on Windows with Python 3.8.2 / CMake 3.16.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached minimal example and its test.py, reproduce the Debug-versus-Release behavior using the listed CMake and Python versions, and inspect the call path through include/pybind11/detail/internals.h and mod.cpp. Compare the failing PyGILState_Ensure stack with the working configurations; done means the minimal module imports without an assertion in the affected Windows debug build.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100