Python Esc cancel does not work in rhino 6 osx

Trying to make a cancel-able python script on mac in rhino 6.
script:

import rhinoscriptsyntax as rs
import Rhino
def TimeConsumingTask():

    for i in range(10000):
        # Was escape key pressed?
        Rhino.RhinoApp.Wait()
        rs.Sleep(1)
        if (scriptcontext.escape_test(False)):
            print "TimeConsumingTask cancelled."
            break
        print i
TimeConsumingTask()

I found these commands to try and help escape_test be detected, but no luck.

Rhino.RhinoApp.Wait()
        rs.Sleep(1)

Anybody have a fix for this or should it be reported as a bug?
Cheers

Hi @tristanryerparke,

I am able to repeat this, and I have logged the issue.

https://mcneel.myjetbrains.com/youtrack/issue/RH-61506

– Dale

Hi @dale,

This still doesn’t work, when for instance used to break out of a while loop! It doesn’t crash Rhino, but the Python script runs ad absurdum and you have to exit the application, if you want it to stop.

Is there a workaround for this?

I attempted this in Version 7 (7.3.21026.13002, 2021-01-26).

It would great, if at least the Cancel button would work! :slight_smile:

Screenshot 2021-01-31 at 10.12.07

1 Like

@Alain - is this something you can help with?

– Dale

Please fix this! It’s super annoying to have to relaunch Rhino each time you want to stop an executing script with no exit strategy.

I see it has been logged. I’ll make it a priority.

In the meantime if you don’t mind a hack:

import os
p = os.path.expanduser("~/stop")
for i in range(10000):
  if os.path.isfile(p):
    break
...

In a terminal window opened to ~ type touch stop to interrupt.

1 Like

Haha, that’s a fun hack! :upside_down_face:

Any news on this?

Sorry, not yet. It’s getting close to the top of my list.

1 Like

No worries! Thanks for the reply.

Hi, have you had time yet to take a look at this?

Hi,
The fix is in v 7.5 RC.
I will ask the developer who fixed it if it can be back ported to 6.x although 6.x updates happen a lot less frequently than 7.x updates.

1 Like

Nice! Is the Cancel button, as well as esc now supported on macOS to break out of running Python scripts?

I’ve already installed the 7.5 release candidate, but it would be nice to offer this to users of version 6, too, since it seems like such an elementary functionality.

A big thanks to everybody who worked on the fix!!

I’ve tested it with a quick example and both the esc key and Cancel now seem to work! Wow, amazing!!