0
$\begingroup$

Sometimes I have a big script and I want to do some tests without it running until the end. I'd like to add a lign of code to terminate the script where I want it without closing blender.

I've found this code online but it quit Blender, which is not what I want, I'd like the equivalent of a CTRL+C in the console.

import sys
sys.exit()
$\endgroup$
0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ This seems to work when place in between two print function for testing purpose. "If the code doesn’t specifically handle exceptions" What does this mean? Why would my code could or couldn't handle exceptions? Thanks! $\endgroup$ – Arthur Blaquart Oct 4 at 7:34
  • $\begingroup$ @ArthurBlaquart Python code can 'trap' exceptions using a 'try: .... except ...:' block. What I meant was, if your code traps exceptions with such a block and your exception is thrown within the 'try:...' section (eg, if within that section it calls one of your functions) then the 'try:...' block might catch your exception, preventing it from filtering back up and stopping the whole script. $\endgroup$ – Rich Sedman Oct 4 at 20:54
  • $\begingroup$ Ok I understand now, cheers :) $\endgroup$ – Arthur Blaquart Oct 5 at 18:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.