pybind / pybind11

Seamless operability between C++11 and Python
https://pybind11.readthedocs.io/
Other
15.83k stars 2.12k forks source link

[BUG]: Cannot reset pybind11 state to "freshly started" #4949

Open gsohler opened 1 year ago

gsohler commented 1 year ago

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

dc9b39596d986aeb061bd3debe52d30e2467dc48

Problem description

Hi, In my project i use embedded python and this uses a python wrapper which is made with pybind11. The Application needs to start the embedded python interpreter several times and also finishes it nicely with Py_FinalizeEx()

Now the problem is:

embedded python is started the 2nd time, python starts python imports a module made with pybind11 Now I get the error: ImportError: generic_type: type "BRepLib_ShellError" is already registered! I believe that the problem is in

inline internals &get_internals_pp(){ static internals internals_pp = nullptr; }

I could not find any mechanism, which can reset this structure. This file should be reset at the same time when i call Py_FinalzeEx()

if that exist, please let me know!

Reproducible example code

No response

Is this a regression? Put the last known working version here if it is.

Not a regression

gsohler commented 1 year ago

I tried to build the example project as documented in

https://pybind11.readthedocs.io/en/stable/basics.html

i get the shared object example binary without issue, but when i started python and type: import example

it does not find. do i need to install the example somwhere ?

zkxjzmswkwl commented 7 months ago

Late reply, but you can use importlib as a work-around for this.

pythonStatus->currentScript = importlib.attr("reload")(pythonStatus->currentScript);