pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

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

Open gsohler opened this issue 2 years ago • 2 comments

Required prerequisites

  • [X] Make sure you've read the documentation. Your issue may be addressed there.
  • [X] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
  • [X] Consider asking first in the Gitter chat room or in a Discussion.

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 avatar Nov 24 '23 07:11 gsohler

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 ?

gsohler avatar Nov 27 '23 10:11 gsohler

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

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

zkxjzmswkwl avatar Apr 27 '24 08:04 zkxjzmswkwl