I am calling python from C# using the following code:
if (!PythonEngine.IsInitialized)
{
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
}
//var pythonScriptCommand = string.Format("{0}", Path.Combine(AppContext.BaseDirectory, "scripts" + Path.DirectorySeparatorChar + "keyringtest.py")); //Path.Combine(AppContext.BaseDirectory, "PythonSampleSystemDiagnostic.py");
IntPtr gs = PythonEngine.AcquireLock();
using (PyScope scope = Py.CreateScope())
{
//foreach (var array in myCommand.Settings)
//{
// Console.WriteLine(string.Join(" ", array)); ;
//}
string fileContent = File.ReadAllText(Path.Combine(@"../../Source/AMD.Agent.Standard.DataExchange/Commands/PythonScripts/", ScriptName));
var file = PythonEngine.Compile(fileContent);
scope.Execute(file);
//dynamic accessToken = scope.Get("get_access_token");
dynamic dataExtract = scope.Get("get_result_http");
//_logger.Info(myCommand.Settings.ToString() + "123123123123");
var dict = myCommand.Settings.ToDictionary(x => x.SettingName, x => x.SettingValue);
var dict123 = JsonConvert.SerializeObject(dict);
dataExtract(token,url1,"PerformanceHistoryPeriod");
//Console.WriteLine(_apxApiService + "123123123123123");
}
PythonEngine.ReleaseLock(gs);
PythonEngine.Shutdown();
Referenced this link: https://mail.python.org/pipermail/pythondotnet/2010-December/001058.html
I am not sure how this works in the sense that if I call this code multiple times in different threads, do all the script executions run in parallel or do they run sequentially, based on the lock.