Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Executing Multiple GIL using Threads#2579

YogesGovindaraj started this conversation inGeneral
Discussion options

Environment

  • 3.0.5
  • 3.9:
  • Windows:
  • 6.0:

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:

  1. 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.

You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
1 participant
@YogesGovindaraj
Converted from issue

This discussion was converted from issue #2541 on April 11, 2025 04:56.


[8]ページ先頭

©2009-2025 Movatter.jp