pybind / pybind/pybind11

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

Open
#4,949 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported get_internals_pp() entry point and the lifecycle around Py_FinalizeEx() and repeated embedded-interpreter startup. There is no reproducible example or file path in the issue, so first trace how pybind11 state is created and retained across interpreter restarts. Done means establishing whether reset support is possible and documenting or addressing the repeated-import failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.