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$
1
  • $\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
    Commented May 25, 2017 at 14:09

2 Answers 2

2
$\begingroup$

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

raise KeyboardInterrupt()
$\endgroup$
1
  • $\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
    Commented Jun 25, 2017 at 10:56
0
$\begingroup$

Could I check if a key is pressed in a loop, and exit the loop if pressed? Ideally, the key press would be cached, so timing wouldn't need to be perfect?

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .