Skip to content

Commit

Permalink
Fixes deadlock on executing gh with script components
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Mar 12, 2024
1 parent 8bef100 commit 6375794
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions src/compute.geometry/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,8 @@ void RhinoCoreStartup()

Rhino.RhinoApp.SendWriteToConsole = true;

// Load GH at startup so it can get initialized on the main thread
Log.Information("(1/3) Loading grasshopper");
var pluginObject = Rhino.RhinoApp.GetPlugInObject("Grasshopper");
var runheadless = pluginObject?.GetType().GetMethod("RunHeadless");
if (runheadless != null)
runheadless.Invoke(pluginObject, null);

Rhino.RhinoApp.SendWriteToConsole = false;

Log.Information("(2/3) Loading compute plug-ins");
var loadComputePlugins = typeof(Rhino.PlugIns.PlugIn).GetMethod("LoadComputeExtensionPlugins");
if (loadComputePlugins != null)
loadComputePlugins.Invoke(null, null);

// NOTE:
// eirannejad 10/02/2024 (COMPUTE-268)
// Ensure RhinoCode plugin (Rhino plugin) is loaded. This plugin registers scripting
// languages and starts the scripting server that communicates with rhinocode CLI. It also makes
// the ScriptEditor and RhinoCodeLogs commands available.
Expand All @@ -78,13 +65,43 @@ void RhinoCoreStartup()
// the script environments (especially python 3) will be initialized. This increases the execution
// time on the first run on any script component. However after that the script components should run
// normally. The scripting environment will only re-initialize when a new version of Rhino is installed.
Log.Information("(3/3) Loading rhino scripting plugin");
if (!Rhino.PlugIns.PlugIn.LoadPlugIn(s_rhinoCodePluginId))
// eirannejad 12/3/2024 (COMPUTE-268)
// This load is placed before Grasshopper in case GH needs to load any plugins published by the
// new scripting tools in Rhino >= 8
Log.Information("(1/3) Loading rhino scripting plugin");
if (Rhino.PlugIns.PlugIn.LoadPlugIn(s_rhinoCodePluginId))
{
Log.Information("Successfully loaded scripting plugin");

// eirannejad 12/3/2024 (COMPUTE-268)
// now configuring scripting env to avoid using rhino progressbar and
// dump init and package install messages to Rhino.RhinoApp.Write
if (Rhino.RhinoApp.GetPlugInObject(s_rhinoCodePluginId) is object rhinoCodeController)
{
((dynamic)rhinoCodeController).SendReportsToConsole = true;
Log.Information("Configured scripting plugin for compute");
}
}
// If plugin load fails, let compute run, but log the error
else
{
// If plugin load fails, let compute run, but log the error
Log.Error("Error loading rhino scripting plugin. Grasshopper script components are going to fail");
}

// Load GH at startup so it can get initialized on the main thread
Log.Information("(2/3) Loading grasshopper");
var pluginObject = Rhino.RhinoApp.GetPlugInObject("Grasshopper");
var runheadless = pluginObject?.GetType().GetMethod("RunHeadless");
if (runheadless != null)
runheadless.Invoke(pluginObject, null);

Rhino.RhinoApp.SendWriteToConsole = false;

Log.Information("(3/3) Loading compute plug-ins");
var loadComputePlugins = typeof(Rhino.PlugIns.PlugIn).GetMethod("LoadComputeExtensionPlugins");
if (loadComputePlugins != null)
loadComputePlugins.Invoke(null, null);

//ApiKey.Initialize(pipelines);
//Rhino.Runtime.HostUtils.RegisterComputeEndpoint("grasshopper", typeof(Endpoints.GrasshopperEndpoint));
}
Expand Down

0 comments on commit 6375794

Please sign in to comment.