1
$\begingroup$

I'm debugging my Python code and I wanted to make my script only execute until a certain line, so I can easily see what is happening.

# python code I want to execute

break_here_and_let_me_read_the_console_output()

# more python code I don't want to execute

I've found out that there's Python's built-in functions like exit() and quit(). The problem is - if I use them, not only my script it terminated, but the whole Blender instance that I was running that script inside is terminated too.

How can I stop only my script, but not Blender itself?

$\endgroup$
  • $\begingroup$ The only way I know to 'terminate' a script is using the return {'FINISHED'}. This is used in operator scripts though... $\endgroup$ – Bert VdB May 25 '17 at 14:09
1
$\begingroup$

Maybe not too elegant, but it will stop the script in the middle and won't close Blender:

raise KeyboardInterrupt()
$\endgroup$
  • $\begingroup$ BaseException is a type you should never raise. I think raising an exception is a good idea, but I would rather choose KeyboardInterrupt or something along those lines. $\endgroup$ – dr. Sybren Jun 25 '17 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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