Stop a script with code?
Depending on what the rest of the code does (and whether it handles any exceptions) you could simply raise an exception with :

raise Exception(“I’ve just triggered termination of my script”)


If the code doesn’t specifically handle exceptions then this will terminate the processing and Blender will report the message raised in the exception.

Obviously, you can replace the text with your own, appropriate to the situation.