If your code is written in a GHPython node, is there a way to exit from the code in the middle of the code?
You can exist from a function by “return”.
You can exit from a for loop by “break”
Buf when your code is at the top level, how to exit?
Or put all your code in a
main() function and
return to exit : this is good practice in Python
if __name__ == ‘__main__’:
Thank you both.
Seems like exit() does not work for GHPython node. I’ll try making a main() function.
You can also do it if you use the
exit() function in your code. More ideally, you can do
sys.exit() which might terminate Python even if you are running things in parallel through the
Note: In order to use the
sys.exit() , you must import it: