You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As i'm working on POC using C# Console Application .I have a requirement on executing multiple "PY.GIL" to handle different tasks using threads . The sample code is able to reach "PY.GIL" initialization after thread call but after that there is no progress the screen got freeze and shows only black screen.
The below is the sample code used:
using System;
using System.Threading;
using Python.Runtime;
Class program
{
public static void Main(string[] args)
{
var virtualpath="Specify the Path";
Runtime.PythonDLL="Specify the DLL path";
.///....Set Environment Variables...
PythonEngine.PythonPath="pythonpath"+"Environment Variables path";
PythonEngine.PythonHome=virtualpath;
PythonEngine.Initialize();
// Creating Threads..
Thread thread1=new Thread(() => RunCode("Executing From Thread1");
Thread thread2=new Thread(() => RunCode("Executing From Thread2");
I'm not getting any errors while reaching "Py.GIL", getting blank screen.
Questions:
How can i execute multiple GIL in parallel to handle python local invocation for different use cases..
I am grateful for any suggestions or insights into resolving this issue.
The text was updated successfully, but these errors were encountered:
Environment
Details
As i'm working on POC using C# Console Application .I have a requirement on executing multiple "PY.GIL" to handle different tasks using threads . The sample code is able to reach "PY.GIL" initialization after thread call but after that there is no progress the screen got freeze and shows only black screen.
The below is the sample code used:
using System;
using System.Threading;
using Python.Runtime;
Class program
{
public static void Main(string[] args)
{
var virtualpath="Specify the Path";
Runtime.PythonDLL="Specify the DLL path";
.///....Set Environment Variables...
PythonEngine.PythonPath="pythonpath"+"Environment Variables path";
PythonEngine.PythonHome=virtualpath;
PythonEngine.Initialize();
// Creating Threads..
Thread thread1=new Thread(() => RunCode("Executing From Thread1");
Thread thread2=new Thread(() => RunCode("Executing From Thread2");
thread1.Start();
thread2.Start();
thread1.join();
thread2.join();
//Shutdown PythonEngine
PythonEnginer.ShutDown();
}
static void RunCode(string threadName)
{
try
{
using(Py.GIL())
{
dynamic math=Py.Import("math");
double sqrtResult=math.sqrt(36);
double powResult=math.pow(2,3);
//print results
Console.WriteLine($"{threadName}: sqrt(25)={sqrtResult}, 2^3={powResult});
Console.ReadLine();
}
}
catch(Exception ex)
{
Console.WriteLine(ex.string());
}
}
}
Additional Details:
Questions:
How can i execute multiple GIL in parallel to handle python local invocation for different use cases..
I am grateful for any suggestions or insights into resolving this issue.
The text was updated successfully, but these errors were encountered: