Callbacks, threads and thead-local storage on 2.2.4 #4029
heuripedes
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Disclaimer: I'm posting this here just in case it's useful for anybody but perhaps this should be in the posted somewhere else.
In pybind11 2.2.4, invoking a Python callback from a C++ function running in a Python-created thread will result in a situation where the Python callback will not have access to thread-local storage initialised on the same thread that invoked the C++ function:
The issue was probably resolved by PR #1211 (see this test code from the PR) which got merged into pybind 2.3.0:
Commands to reproduce
For pybind 2.2.4:
pip install cppimport "pybind11==2.2.4" &>/dev/null && rm cpp_module*cpython*so && python tlstest.py 2>/dev/null
For pybind 2.3.0:
pip install cppimport "pybind11==2.3.0" &>/dev/null && rm cpp_module*cpython*so && python tlstest.py 2>/dev/null
Code to reproduce:
Note 1: make sure you have python-dev (I'm using 3.9) and a compiler.
Note 2: copy even the comments otherwise
cppimports
might not be able to correctly build the native module.cpp_module.cpp
tlstest.py
Beta Was this translation helpful? Give feedback.
All reactions