Scriptcontext.escape_test not reset at start of RhinoCode execution

In 8.6.24101.5001, 2024-04-10,

this script
#! python 2

import Rhino
import scriptcontext as sc

def anotherCheck(s):
    if sc.escape_test(throw_exception=False, reset=True):
        print("escape_test WAS reset {} loop routine.".format(s))
    else:
        print("escape_test was NOT reset {} loop routine.".format(s))

print('-'*40)

anotherCheck("before")

for i in range(10000, 0, -1):
    Rhino.RhinoApp.CommandPrompt = "Press Esc now ({})".format(i)
    if sc.escape_test(throw_exception=False):
        print("Esc was pressed.")
        break

# anotherCheck("after")

outputs

----------------------------------------
escape_test was NOT reset before loop routine.
Esc was pressed.

when executed via either

  • Start Debugging or Start Without Debugging button in Rhino Python Editor (_EditPythonScript).
  • _RunPythonScript with the script containing #! python 2 or neither #! python 2 or #! python3.

However, it then outputs

----------------------------------------
escape_test WAS reset before loop routine.
Esc was pressed.

when executed via either

  • Run active script button in Script Editor regardless if the script contains #! python 2 or #! python3.
  • _RunPythonScript with #! python3 in place of #! python 2.

Additional observations:

  1. escape_test does not return True when the initial (new Rhino instance) execution is via RhinoCode.
  2. The reset is required even after first executing the script via non-RhinoCode.
  3. escape_test state is retained at the beginning of the next RhinoCode execution, regardless of which script is executed.

Same/similar issue here using Rhino 8 SR11 RC2
(Would have created a new topic, but found this unanswered one instead)

In the past, I always used

if sc.escape_test(): return

without any arguments inside loops. By only using EditPythonScript or RunPythonScript with IronPython scripts, pressing Escape during a long loop works as expected.

Currently, I must use

if sc.escape_test(reset=True): return

with the reset argument set to True if I want to use the modern ScriptEditor for both IronPython and Python3 to get the Escape key working (kind of) consistently.

@eirannejad

Added this ticket and will push a fix for this ASAP

RH-83435 sc.escape_test does not reset between script runs

Even previous to V8, there have been discrepancies between the behavior of sc.escape_test when running a script via _EditPythonScript or _RunPythonScript and running from a command, .rhp, or .rhi.

An example: V7 bug in running script from button, ESC is not released

I’d rather escape_test be consistent regardless how the script is being called.

What is a scenario when it useful for reset to be set to False and remain set before and after escape_test returns True?