Python break

Does anyone know if there is a way to stop a python script midway?

For instance, what if I write in an endless loop into the node? is there a way to escape it without shutting down revit?

No, there is a way to write a “while” loop so that it terminates itself even if it spins out of control. Please get into a habit of putting a counter inside your loops and breaking the loop when you reach a limit. That will save you some time in restarting Revit alone…:slight_smile:

the halting problem :slight_smile:

1 Like

But if you just want to stop executing the python node you could try using

import sys

sys.exit(0)


 

where 0 is whatever exit code you will exit with… this will probably bubble an exception to the python node… potentially causing a crash

 

I would stick to Konrad’s advice and avoid while loops when unnecessary or build escape counters into them.

Nice read Michael. Thanks for sharing!

Yes, thanks for sharing. I certainly could use “best practices” for scripting.

I do wonder if this may be some functionality that could be added. Somehow I recall that in the days of Basic & Logo (!) one could use <ctrl-G> or <ctrl-C> to stop a loop.

I think that Generative components also has a similar thing.