-
Notifications
You must be signed in to change notification settings - Fork 268
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
Feature/custom exit codes in tools #2566
Conversation
src/ctapipe/core/tool.py
Outdated
exit_status = err.code | ||
self.log.exception("Caught SystemExit with exit code %s", exit_status) | ||
Provenance().finish_activity( | ||
activity_name=self.name, status="SystemExit" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the original plan was to not allow any random exit code, only a pre-defined set. If we need to have arbitrary exit codes (I guess the use case here is for workflow handling?), at the very least the code that was used should be stored in the provenance. Just recording "SystemExit" loses the reason for the exit happening. So we should either add a field to the provenance, or include the code in the status. The latter is less ideal since it would require parsing, and means the sets of possible status values is not finite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the use case here is workflow handling. And the exit codes should not be completely randomly, but rather controlled by the corresponding ICD in our case. However, given that ctapipe
is a community product, I'm a bit hesitant to introduce such a dependency here. On the other hand, I fully agree with your point that the exit code should be stored in provenance. Here before making a move, I'd like to discuss options.
So far, the possible statuses are ["completed", "interrupted", "error"]
plus "SystemExit" I've added. I'm not sure what the subsequent purpose of this field. Is it just a human-readable label? If so, I would add another field, exit_code
or just code
where an actual exit code will be stored and change the list of possible statuses to ["success", "interrupted", "error", "partial_success"]
or similar. On the other hand, if the status
field is supposed to be machine-readable, shall it just keep the exit code value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far, the possible statuses are ["completed", "interrupted", "error"] plus "SystemExit"
I think SystemExit
is not needed. The only reason to have a non-zero exit code is by definition some kind of "error".
If so, I would add another field, exit_code
Yes, I think adding the exit_code
field is the way to go.
The problem is a bit that in the current scheme, Acitivity
is not mapped one-to-one to a command-line tool.
"partial_success"
I think that's a bit hard to define at the Tool
logic-level, however, what we could do is to let the implementation set this status already
Provenance().current_acitvity.status = "partial_success"
and in that case we don't override it in Tool.run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, this should be default in the _ActivityProvenance
helper class constructor:
ctapipe/src/ctapipe/core/provenance.py
Lines 220 to 230 in 2b70207
def __init__(self, activity_name=sys.executable): | |
self._prov = { | |
"activity_name": activity_name, | |
"activity_uuid": str(uuid.uuid4()), | |
"start": {}, | |
"stop": {}, | |
"system": {}, | |
"input": [], | |
"output": [], | |
} | |
self.name = activity_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys.executable
That's always the python interpreter, right? It won't be the cli tool name even if used via an entry point installed script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the default value in the current code. It is overridden in the Tool.run()
function:
ctapipe/src/ctapipe/core/tool.py
Line 409 in 2b70207
Provenance().start_activity(self.name) |
- Add "exit_code" field to provenance dictionary - Update the possible provenance status values to ["success", "interrupted", "error", "partial_success"] - Making the "partial_success" status default - It is overridden in finish_activity with a default "success"
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
Analysis Details1 IssueCoverage and DuplicationsProject ID: cta-observatory_ctapipe_AY52EYhuvuGcMFidNyUs |
Following a need in custom exit codes in
ctapipe.core.Tool
, I've implemented an extra catch ofSystemExit
that can be generated during the tool's execution phase that also performs a clean up in the same fashion as in general Exception interception and propagates the exit code further down.