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.
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.
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)
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.