diff --git a/src/NodeServices/PythonServices.cs b/src/NodeServices/PythonServices.cs index 7cd8745622d..863a6082c82 100644 --- a/src/NodeServices/PythonServices.cs +++ b/src/NodeServices/PythonServices.cs @@ -126,24 +126,22 @@ internal static readonly Lazy private Action customizeEngine; /// - /// Use this function to customize Python engine initialization. - /// This function will be called only once on all existing or future python engines (on PythonEngineAdded). + /// Provides an easy way to run initialization code on PythonEngine instances /// - public Action CustomizeEngine + /// Action to be called on PythonEngines. + /// If true, the action will be called on existing PythonEngines. If false the action will be called when new Python engines are added. + public void ApplyInitializationAction(Action initAction, bool callOnExistingEngines = true) { - set + if (initAction != null) { - customizeEngine = value; - if (customizeEngine != null) + customizeEngine = initAction; + + if (callOnExistingEngines) { - try + foreach (var engine in AvailableEngines) { - foreach (var engine in AvailableEngines) - { - customizeEngine(engine); - } + initAction(engine); } - catch { } } } }