mcneel / ghpython

A Grasshopper component for Rhino.Python
http://www.food4rhino.com/project/ghpython
117 stars 34 forks source link

No way to break/Ctrl-C out of python script #68

Open dantaeyoung opened 10 years ago

dantaeyoung commented 10 years ago

Hi,

First of all, thanks for such a wonderful and helpful script.

It seems that right now, there's no way to break or Ctrl-C a Python script -- for example, an infinite "while(True)" loop will run forever, consequently crashing Rhino. Of course, I'm not running infinite loops, but this means that a loop with faulty logic will crash Rhino and Grasshopper, erasing any progress done since the last time saved.

Am I missing something, and is there a way to just break a Python script running inside the Python Grasshopper Component?

saeranv commented 10 years ago

You can code in an Esc break: http://www.grasshopper3d.com/forum/topics/make-a-custom-component-cancel-able?commentId=2985220%3AComment%3A883361 , introduced to me by @mostaphaRoudsari .

You can see an example for Python here, I used it for one of the Ladybug components: https://github.com/mostaphaRoudsari/ladybug/blob/master/src/Ladybug_SolarFan_alt.py#L801

ETA: It looks like it will work as long as you embed it within a loop, but not for recursive calls.

chojje commented 6 years ago

@saeranv the link above is broken, where can I find this?