Skip to content

Commit

Permalink
Merge pull request #776 from Uniplore-X/pr-master
Browse files Browse the repository at this point in the history
Fix `ScriptActivities` bug for `python 3.11` runtime
  • Loading branch information
skadefro authored Sep 12, 2023
2 parents abad393 + ec55f7b commit 2ee8f1c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
17 changes: 11 additions & 6 deletions OpenRPA.Script/Activities/InvokeCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ protected override void Execute(CodeActivityContext context)
Execute(context, code, language, Arguments, PipelineOutput);
}

public static void InitPython()
{
if (python_doinit)
{
Python.Runtime.PythonEngine.Initialize();
_ = Python.Runtime.PythonEngine.BeginAllowThreads();
python_doinit = false;
}
}

public void Execute(CodeActivityContext context, string code, string language, Dictionary<string, Argument> Arguments,
OutArgument<Collection<System.Management.Automation.PSObject>> PipelineOutput)
{
Expand Down Expand Up @@ -365,12 +375,7 @@ public void Execute(CodeActivityContext context, string code, string language, D
IntPtr lck = IntPtr.Zero;
try
{
if (python_doinit)
{
Python.Runtime.PythonEngine.Initialize();
_ = Python.Runtime.PythonEngine.BeginAllowThreads();
python_doinit = false;
}
InitPython();
// lck = PythonEngine.AcquireLock();
doRelease = true;
using (Python.Runtime.Py.GIL())
Expand Down
14 changes: 13 additions & 1 deletion OpenRPA.Script/Activities/ScriptActivities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,19 @@ protected override void Execute(CodeActivityContext context)

if (language == "Python")
{
args = ToPythonObject(args);
try
{
InvokeCode.InitPython();
using (Python.Runtime.Py.GIL())
{
args = ToPythonObject(args);
}
}
catch (Exception ex)
{
Log.Warning(ex.ToString());
throw new Exception("Failed for 'ToPythonObject': " + ex.ToString());
}
}

rpa_args.Set(context, args);
Expand Down

0 comments on commit 2ee8f1c

Please # to comment.