-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Labels
triageNew bug, unverifiedNew bug, unverified
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
2.12.0
Problem description
All the python parts happen inside a function with a scoped_interpreter. I call the function twice from main. The first time, everything works. The second time it fails. And this is only if numpy is imported. Output error is different in different versions of python and numpy. But I think it is related to numpy's CPU dispatcher.
Reproducible example code
#include <iostream>
#include <pybind11/embed.h>
namespace py = pybind11;
void test() {
py::scoped_interpreter guard;
try {
py::exec(R"(
import numpy
print("module loaded")
)");
} catch (py::error_already_set &e) {
std::cerr << e.what() << "\n";
}
}
int main() {
// py::scoped_interpreter guard; // If the `guard` is in the `main` scope, there is no issue.
test();
test(); // this call fails to import numpy
return 0;
}
Is this a regression? Put the last known working version here if it is.
Not a regression
cartercocke
Metadata
Metadata
Assignees
Labels
triageNew bug, unverifiedNew bug, unverified