Comments (3)
I think I can explain why the exception is not working in a helpful way for routine1
in numpy/numpy#7855, but I don't think I can think of anything better than solution 2.
My mental model of python's exception handling (no doubt vastly simplified or wrong) is that there is a flag in the interpreter that is set when an exception is raised. This is checked by the interpreter each time a python function is called, and if the flag is set instead of the python function being called the call stack is examined and the exception handling machinery activated. To operate, the python interpreter calls a lots of different interpreter functions (written in C). Some of these functions will do the job of checking and setting python's exception flag. The C functions have their own call stack and frame pointer which works in the same way as for any other compiled code. An interpreter function calling another interpreter function does not result in the exception flag being examined. When f2py is used to compile a Fortran subroutine you end up with something that looks like a python function and a function that behaves like an interpreter function. When you call routine1
from python, it calls routine2
as an "interpreter" function, this calls f
and sets the exception flag. However, the the state of that flag is not checked on return from routine2
(this is just one fortran subroutine calling another, it does not know that it is running inside the process running the python interpreter) but only when you get back to something that looks like a "python function" (routine1
). One thing to note is that even for the routine1
call, by the time you get back to the python interpreter you do end up with an exception (no more python gets run and the exception is raised) it's just that all of routine2
has been run by this point. The callback machinery seems to know about the exception (I guess this is where the "Call-back cb_pystop_in_routine2__user__routines failed." line comes from) but does not seem to want to do anything about it. I don't know if it would be possible to fiddle with the interpreter call stack at this point to skip the rest of routine2
, I suspect not. I've tried fiddling around with the callback function (e.g. making it call another python function which raises the exception, having a return value) but nothing seems to stop the rest of routine2
being run.
So, I think solution 2 is probably the best bet. The other advantage of this is that it would be possible to avoid stop
in Fortran if people want to run SHTOOLS inside of MPI (mpi_abort()
is probably better) or want to arrange for a core dump if they pass duff data into an SHTOOLS routine. We've got some fairly fancy (overly baroque?) implementations of exception handling in Fortran inside of FoX but these are probably overkill and are not designed for performance critical code.
from shtools.
That sound about right to me. Thanks!
from shtools.
see: #59
from shtools.
Related Issues (20)
- Earth2012 and Earth2014 not callable HOT 2
- NameError: name 'shcoeffs' is not defined HOT 1
- Release SHTOOLS 4.10.4
- Cannot install M1-Mac by pip HOT 4
- Call to dggglm SHExpandLSQ HOT 1
- Installation on Python 3.10.12 error: metadata-generation-failed, No module named 'numpy.distutils' HOT 2
- Install issue can't build wheel. (Using Pycharm) HOT 1
- Exporting grid data to 3D model
- Sampling is incorrectly set when using DHRealGrid() class. HOT 1
- Release SHTOOLS 4.11 HOT 1
- Meson can't determine version of pyshtools when installing from a source tarball HOT 5
- jupyter is an (undeclared) build-time dependency HOT 6
- Compilation error on MacOS Sonoma HOT 7
- issue when calling pyshtools.spectralanalysis.SHReturnTapersMap HOT 6
- installing pyshtools lead to error: metadata-generation-failed (PyCharm) HOT 3
- Error message when attempting to install pyshtools on Mac OS X 14.2.0 HOT 14
- Release SHTOOLS 4.12.0 HOT 1
- Implement ducc backend to pyshtools gravity and magnetic classes HOT 2
- Help! I can't install pyshtools!!! HOT 1
- Apple silicon M1 macOS 14.4.1 library 'lapack' not found HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shtools.