Skip to content
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

raise python errors instead of c++ abort #533 #523

Closed
archibate opened this issue Feb 23, 2020 · 4 comments
Closed

raise python errors instead of c++ abort #533 #523

archibate opened this issue Feb 23, 2020 · 4 comments
Labels
feature request Suggest an idea on this project

Comments

@archibate
Copy link
Collaborator

archibate commented Feb 23, 2020

I would like to throw python exception instead of getting c++ abort for some of taichi errors (eg. imread-file-not-found, new-var-after-materialization) so that people could catch them in python and deal with it.

Describe the solution you'd like

When C++ code invoked from Python throws an std::exception, it is automatically converted into a Python Exception.

So, throw std::exception in TI_ERROR, instead of std::raise. Doing this, you'll got a RuntimeError in python-scope.

Additional comments
See https://pybind11.readthedocs.io/en/stable/advanced/exceptions.html for more details.

@archibate archibate added the feature request Suggest an idea on this project label Feb 23, 2020
@archibate
Copy link
Collaborator Author

archibate commented Feb 23, 2020

Also helps pytest to show messages when error occur in C++ scope instead of exit silently with -1:

(opengl) [bate@archit taichi]$ pytest tests/python/test_loops.py
============================================= test session starts =============================================
platform linux -- Python 3.8.1, pytest-5.3.4, py-1.8.1, pluggy-0.13.1
rootdir: /home/bate/Develop/taichi
plugins: xdist-1.31.0, forked-1.1.3
collected 7 items                                                                                             

tests/python/test_loops.py ...(opengl) [bate@archit taichi]$ echo $?
255

@archibate
Copy link
Collaborator Author

TODO: @archibate you gonna work on this tonight!

@archibate archibate changed the title raise python errors instead of c++ abort raise python errors instead of c++ abort #533 Feb 25, 2020
yuanming-hu pushed a commit that referenced this issue Feb 27, 2020
…cope #523 (#533)

* throw exception instead of raise(SIGABRT) to obtain RuntimeError in Python-scope

* remove strchr
@archibate
Copy link
Collaborator Author

archibate commented Feb 27, 2020

TODO(archibate or yuanming-hu): ti.get_runtime().trigger_gdb config var, by TI_TRIGGER_GDB=1, must disable during pytest, go for Kerbal Space Program now.

@archibate
Copy link
Collaborator Author

Seems already solved by @yuanming-hu. Closing now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Suggest an idea on this project
Projects
None yet
Development

No branches or pull requests

1 participant