pybind / pybind11

Seamless operability between C++11 and Python

Home Page:https://pybind11.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

gsohler opened this issue · comments

Required prerequisites

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

dc9b395

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

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 ?

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

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