Comments (6)
Possibly related to this, in the CMIP6 example the following command is used:
error_flag = cmor.dataset_json("Test/test_python_CMIP6_experimentID.json")
In the CMOR2 User Guide, both Fortran and C return 0 upon success, whereas Python returns None. Is there a way for the exit code to be returned to pywrapper.py
in the same way as Fortran and C? I understand there are cases where CMOR should explicitly fail, but if the underlying function returns the exit code rather than exiting itself, couldn’t the code in pywrapper.py
check the exit code and then raise an exception / return the correct exit code, depending on what you want CMOR3 to do in each case?
from cmor.
- Example 1 I created this message for you. I return as soon as I detect that you did not call
cmor.setup()
.cmor.setup()
set all memory to 0, so it is very important - Example 2 I just check the code and
fclose()
is called only bycmor_close()
, I will look at change this behavior so that the file is open/close for each error. This should not be too difficult. - No exit to python, not sure, I am sending a SIGINT signal, I tried SIGTERM, but you get the "Abort" message on red hat. I tried other signal, but I need to program to stop, already, I have noticed that python will run the function and only send the signal when all functions have ``return`(ed). That creates weird behavior. I just did not want to "kill -9" the process the way it used to do.
- I am not sure what you mean by (3). I do not have control of the "Keyboard Interrupt" message after the SIGINT signal has been sent. I can look, but that seems hard.
- I think returning (0) instead of "None" in
python
is a great idea. It will help myunittest
a lot. I'll try to do this next week.
from cmor.
Example 1: I created this message for you. I return as soon as I detect that you did not call cmor.setup(). cmor.setup() set all memory to 0, so it is very important
No exit to python, not sure, I am sending a SIGINT signal, I tried SIGTERM, but you get the "Abort" message on red hat. I tried other signal, but I need to program to stop, already, I have noticed that python will run the function and only send the signal when all functions have `return(ed). That creates weird behavior. I just did not want to "kill -9" the process the way it used to do.
The Python interpreter is terminated when CMOR detects that cmor.setup()
was not called because an exit(1)
is used (https://github.com/PCMDI/cmor/blob/master/Src/cmor.c#L598) rather than SIGINT
. Is there any chance that a SIGINT
signal can be sent in this case, so that the Python interpreter is not terminated?
Example 2: I just check the code and fclose() is called only by cmor_close(), I will look at change this behavior so that the file is open/close for each error. This should not be too difficult.
Great, thank you! :)
I am not sure what you mean by (3). I do not have control of the "Keyboard Interrupt" message after the SIGINT signal has been sent. I can look, but that seems hard.
I haven't had much luck with figuring out if there is a way to send the log message to the exception :( I did find a way to change the type of exception though :) The following changes can be made to https://github.com/PCMDI/cmor/blob/master/Lib/pywrapper.py#L5 to raise a specific exception when a SIGINT
signal is caught:
class CMORError(Exception):
def __init__(self, message):
super(CMORError, self).__init__(message)
def sig_handler(signum, frame):
message = 'Problem with CMOR. Please check the logfile (if defined).'
raise CMORError(message)
signal.signal(signal.SIGINT, sig_handler)
I ran some quick tests and this seems to work for me (i.e., I can catch all CMORError
exceptions). I think this would be better than a KeyboardInterrupt
exception :)
I think returning (0) instead of "None" in python is a great idea. It will help my unittest a lot. I'll try to do this next week.
Great, thank you! :)
from cmor.
I haven't had much luck with figuring out if there is a way to send the log message to the exception :(
Unless @doutriaux1 comment can help?
from cmor.
Example 1: I created this message for you. I return as soon as I detect that you did not call cmor.setup(). cmor.setup() set all memory to 0, so it is very important
No exit to python, not sure, I am sending a SIGINT signal, I tried SIGTERM, but you get the "Abort" message on red hat. I tried other signal, but I need to program to stop, already, I have noticed that python will run the function and only send the signal when all functions have `return(ed). That creates weird behavior. I just did not want to "kill -9" the process the way it used to do.
The Python interpreter is terminated when CMOR detects that
cmor.setup()
was not called because anexit(1)
is used (https://github.com/PCMDI/cmor/blob/master/Src/cmor.c#L598) rather thanSIGINT
. Is there any chance that aSIGINT
signal can be sent in this case, so that the Python interpreter is not terminated?
That is right, I decided to call exit() since there will be no log, cmor.setup() was not called. Without it, no log file is opened to write messages. I just abandon boat and print this message to the user. If I send a SIGINT, all functions need to return which creates a lot of unnecessarily and confusing messages. cmor.setup() is a must and have to be called before anything. Think of it like a __init__()
in Python.
Example 2: I just check the code and fclose() is called only by cmor_close(), I will look at change this behavior so that the file is open/close for each error. This should not be too difficult.
Great, thank you! :)
I am not sure what you mean by (3). I do not have control of the "Keyboard Interrupt" message after the SIGINT signal has been sent. I can look, but that seems hard.
I haven't had much luck with figuring out if there is a way to send the log message to the exception :( I did find a way to change the type of exception though :) The following changes can be made to https://github.com/PCMDI/cmor/blob/master/Lib/pywrapper.py#L5 to raise a specific exception when a
SIGINT
signal is caught:class CMORError(Exception): def __init__(self, message): super(CMORError, self).__init__(message) def sig_handler(signum, frame): message = 'Problem with CMOR. Please check the logfile (if defined).' raise CMORError(message) signal.signal(signal.SIGINT, sig_handler)
I ran some quick tests and this seems to work for me (i.e., I can catch all
CMORError
exceptions). I think this would be better than aKeyboardInterrupt
exception :)
I am fine with the Keyboard Interrupt, if CMOR3 user input file is fine, we won't have a critical error.
At this moment, I am writing the "CMIP6 Validator" using the Control Vocabulary, but I'll try it when I get a chance.
I think returning (0) instead of "None" in python is a great idea. It will help my unittest a lot. I'll try to do this next week.
Great, thank you! :)
from cmor.
Closing in favour of #86 and #87.
from cmor.
Related Issues (20)
- Exposing latest netcdf 4.9.x library functionality: quantize, zstandard HOT 13
- Remove unused attributes when processing CMIP6Plus datasets HOT 14
- Exposing latest netcdf 4.9.x library functionality: quantize, zstandard HOT 48
- unclear warning... HOT 5
- bounds required on singleton lon and lat? HOT 5
- avoid attributes of bounds of auxilliary coordinates (`vertices_latitudes` / `vertices_longitude`) HOT 5
- Calibrating CMOR3 & 4 forward development plans HOT 7
- CMOR 3.8.0 Release HOT 4
- Update README.md to remove v3.7 reference
- default `realm = "REALM"` is always written although not required by CV HOT 2
- order in `required_global_attributes` matters HOT 1
- input time type as INT HOT 3
- CircleCI current image deprecated HOT 1
- Numpy 2.0 compatibility issue HOT 2
- File output size and chunking HOT 10
- Message Logging generates duplicated output lines
- DESTDIR support HOT 2
- Failure invoking set_deflate HOT 1
- user defined grid mapping
- Add CITATION.cff file HOT 5
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 cmor.