Commit 98ffcdd9 authored by Tom Niget's avatar Tom Niget

Use subinterpreters to handle Python-C++-Python calls

parent 4e07f391
...@@ -394,4 +394,24 @@ namespace detail { ...@@ -394,4 +394,24 @@ namespace detail {
} }
} }
#ifdef TYPON_EXTENSION
class SubInterpreter {
PyThreadState* main;
PyThreadState* sub;
public:
SubInterpreter() {
main = PyThreadState_Get();
sub = Py_NewInterpreter();
}
~SubInterpreter() {
Py_EndInterpreter(sub);
PyThreadState_Swap(main);
}
};
#else
using SubInterpreter = py::scoped_interpreter;
#endif
#endif // TYPON_BUILTINS_HPP #endif // TYPON_BUILTINS_HPP
...@@ -59,7 +59,7 @@ class ModuleVisitor(BlockVisitor): ...@@ -59,7 +59,7 @@ class ModuleVisitor(BlockVisitor):
yield f"> arg{i}" yield f"> arg{i}"
yield ") {" yield ") {"
yield "py::scoped_interpreter guard{};" yield "SubInterpreter lock{};"
yield f"return py::module_::import(\"{mod}\").attr(\"{name}\")(" yield f"return py::module_::import(\"{mod}\").attr(\"{name}\")("
for i, argty in enumerate(fty.parameters): for i, argty in enumerate(fty.parameters):
if i != 0: if i != 0:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment