-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[BUG] Crash invoking Python function which fails with RecursionError #2505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
First, you didn't finalize the interpreter. Second, you didn't declare #include <pybind11/embed.h>
namespace py = pybind11;
int main() {
py::scoped_interpreter g;
py::module gSymPy = py::module::import("sympy");
py::object gParse = gSymPy.attr("parse_expr");
py::object solveset = gSymPy.attr("solveset");
py::object parse_expr = gSymPy.attr("parse_expr");
py::object result = solveset(parse_expr("1/sqrt(x)"));
} The last line raises
The above is with pybind11 2.5.0, python 3.8.5 and sympy 1.6.2. However, I can see some objective-c in your snippet, which I know nothing about. |
Right, thank you. I left out the try/catch portion of my source:
I seeing the crash on the call without seeing any C++ exceptions thrown here. I wonder what is different in my embedded configuration. |
All python exceptions get translated to |
On further investigation, the one additional aspect in the embedding app which I had left out mistakenly thinking it irrelevant is that the app creates a pthread dedicated to Python which always holds the GIL and processes a command queue. On macOS here, pthread_create defaults to a 512K stack size for the thread, which is insufficient. Increases the thread's stack size to 2MB eliminated the crash so the exception now appears and is handled gracefully. Thank you for your patience. |
Uh oh!
There was an error while loading. Please reload this page.
Issue description
With SymPy 1.6.1 and Python 3.8 embedded in C++,
solveset(1/sqrt(x))
crashes.solveset(1/sqrt(x))
fails reportingRecursionError: maximum recursion depth exceeded
in the interactive Python interpreter. With embedded Python, it crashes the embedding app with an address error.Reproducible example code
crashes the embedding application with an address error 4084 stack frames deep.
Is there a way to handle this gracefully in the embedding app without fixing the underlying SymPy bug?
(#sympy/sympy#20097)
The text was updated successfully, but these errors were encountered: