Skip to content

Instantly share code, notes, and snippets.

@kohnakagawa
Last active June 1, 2020 13:54
Show Gist options
  • Select an option

  • Save kohnakagawa/a5fc1e974e118615031730c7ab8d5b71 to your computer and use it in GitHub Desktop.

Select an option

Save kohnakagawa/a5fc1e974e118615031730c7ab8d5b71 to your computer and use it in GitHub Desktop.
#include <pybind11/pybind11.h>
#include <stdexcept>
void func() {
// NOTE: If Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS are not commented out, calling "func" exits with SIGSEGV.
// Py_BEGIN_ALLOW_THREADS
throw std::logic_error("an exception occurred");
// Py_END_ALLOW_THREADS
}
PYBIND11_MODULE(example, m) {
m.doc() = "Example pybind11"; // optional module docstring
m.def("func", func, "throw exception");
}
@kohnakagawa
Copy link
Author

kohnakagawa commented Jun 1, 2020

g++ -O3 -Wall -shared -std=c++11 -fPIC `python3 -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment