Exit early from a Python node

There was a topic in 2020 about ways to exit early from a Python script, e.g. via sys.exit(1)
Best way to exit early from a Python node

A KNIME Team member wanted to open a feature request about this issue.
I’m encountering the same problem at the moment and would like to know if there has been a feature request about that and if there was a solution.

Dear @florian_eck,

the feature request has been opened and declined (AP-14532).

We encourage putting the script into a method (see your forum link and in there in the “#Do stuff” line), which can return then if the exit is desired.

Does that help?

Best regards
Steffen

Ok, I will then refactor the script to use a main() method.

The problem originated from the fact that the script is used both standalone and in a KNIME workflow (with small adjustments like import packages and reading input)

1 Like

I see. Maybe have a parameter within_knime in the method which you can toggle depending where you use the script (assuming that you load it from an outside file) so that the small adjustments are only executed when needed.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.