Exit Grasshopper and Rhino started by python subprocess

I also got the problem described in the following threads:

import rhinoscriptsyntax as rs
rs.Command("_Exit")
rs.Exit()

don’t work when executed in an ‘if’ clause. If I click “Test code”, it works as expected.


I call the python component for closing Rhino and GH at the end of my solution. I could kill the process from within a python component, but that could lead to license issues (Killing a Rhino.exe process does not free a license in Zoo)at

Has anything changed on this topic or is it still a problem?

They both seem to work here, on Rhino 6.29.20238.11501, 2020-08-25, from inside Grashopper. When I change either toggle to True, Rhino prompts to save the files then exits.

exit-in-if-ghpython.gh (6.3 KB)

And directly in Rhino Python editor, only rs.Exit() works:

import rhinoscriptsyntax as rs

exit = True

if exit:
    rs.Exit()

1 Like

Hello Pierre,

I have to apologize for missing out on important steps needed for replicating the behaviour.

I tried to use Grasshopper with Rhino 7 WIP headless, but had no success, so I load Rhino and Grasshopper, execute a solution and then want to close both as a workaround. Rhino.Exit() works as expected if Rhino is started by the user and not by a subprocess.

Rhino and Grasshopper from a python subprocess:

import subprocess

edit_path = r"path\_exit_example.gh"
com = f"C:\\Program Files\\Rhino 6\\System\\Rhino.exe /nosplash /runscript=\"!-RunPythonScript (import sys;sys.path.append(r'folder');import rhino_script;rhino_script.runGHDef(r'{edit_path}'))\""
subprocess.call(com)

rhino_script.runGHDef

import Rhino


def runGHDef(path):
    Gh = Rhino.RhinoApp.GetPlugInObject("Grasshopper")
    if not Gh:
        return

    Gh.LoadEditor()
    Gh.CloseAllDocuments()
    ok = Gh.OpenDocument(path)
    if not ok:
        return

Use the attached exit_example.gh file to replicate the error.
_exit_example.gh (8.8 KB)

Thanks for your help.