Memory management issues when importing pybind extension via different paths #3847
Unanswered
alexander-soare
asked this question in
Q&A
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.
Uh oh!
There was an error while loading. Please reload this page.
-
I've distilled this problem into a minimal reproducible example.
Here's the folder structure
ext.cppjust implements hello world as a pybind extension.It can be built (cd into the build dir first) with:
g++ -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) ../ext.cpp -o ext$(python3-config --extension-suffix)Running
python a.pywhile in thefoodirectory raises no errors:Running
python b.pywhile in the root directory raises no errorsBut, running
python c.pywhile infooraisesfree(): invalid pointerand54630 abort (core dumped)after the script finishes executing the final line.;The problem can be distilled even further into
d.pywhich raises the same errors as
c.pySo to sum up, the error seems to be raised when a pybind extension is imported twice in one interpreter session, but via different import paths.
I've been working around this by trying to import via the same path no matter where I am. Any ideas for the root cause and real fix?
Beta Was this translation helpful? Give feedback.
All reactions