Title: Executing Multiple GIL using Threads · Issue #2541 · pythonnet/pythonnet · GitHub
Open Graph Title: Executing Multiple GIL using Threads · Issue #2541 · pythonnet/pythonnet
X Title: Executing Multiple GIL using Threads · Issue #2541 · pythonnet/pythonnet
Description: 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" init...
Open Graph Description: 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 sa...
X Description: 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 th...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/2541
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Executing Multiple GIL using Threads","articleBody":"### Environment\r\n\r\n- 3.0.5\r\n- 3.9:\r\n- Windows:\r\n- 6.0:\r\n\r\n### Details\r\n\r\n- 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.\r\n\r\n- The below is the sample code used:\r\nusing System;\r\nusing System.Threading;\r\nusing Python.Runtime;\r\nClass program\r\n{\r\npublic static void Main(string[] args)\r\n{\r\nvar virtualpath=\"Specify the Path\";\r\nRuntime.PythonDLL=\"Specify the DLL path\";\r\n.///....Set Environment Variables...\r\nPythonEngine.PythonPath=\"pythonpath\"+\"Environment Variables path\";\r\nPythonEngine.PythonHome=virtualpath;\r\nPythonEngine.Initialize();\r\n// Creating Threads..\r\nThread thread1=new Thread(() =\u003e RunCode(\"Executing From Thread1\");\r\nThread thread2=new Thread(() =\u003e RunCode(\"Executing From Thread2\");\r\n\r\nthread1.Start();\r\nthread2.Start();\r\n\r\nthread1.join();\r\nthread2.join();\r\n//Shutdown PythonEngine\r\nPythonEnginer.ShutDown();\r\n}\r\nstatic void RunCode(string threadName)\r\n{\r\ntry\r\n{\r\nusing(Py.GIL())\r\n{\r\ndynamic math=Py.Import(\"math\");\r\ndouble sqrtResult=math.sqrt(36);\r\ndouble powResult=math.pow(2,3);\r\n//print results\r\nConsole.WriteLine($\"{threadName}: sqrt(25)={sqrtResult}, 2^3={powResult});\r\nConsole.ReadLine();\r\n}\r\n\r\n}\r\ncatch(Exception ex)\r\n{\r\nConsole.WriteLine(ex.string());\r\n}\r\n}\r\n}\r\n\r\n\r\nAdditional Details:\r\n1) I'm not getting any errors while reaching \"Py.GIL\", getting blank screen.\r\n\r\nQuestions:\r\n\r\nHow can i execute multiple GIL in parallel to handle python local invocation for different use cases..\r\nI am grateful for any suggestions or insights into resolving this issue.\r\n","author":{"url":"https://github.com/YogesGovindaraj","@type":"Person","name":"YogesGovindaraj"},"datePublished":"2025-01-07T06:48:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2541/pythonnet/issues/2541"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e2837cb9-32b2-c6a6-694d-d1b7f5cf0a42 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E22:3D59DC:716995:953CD6:69719F67 |
| html-safe-nonce | 70d6cd990497c91c989afceace4f33304774a2fa401ace45ebe2703e7211f7ec |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTIyOjNENTlEQzo3MTY5OTU6OTUzQ0Q2OjY5NzE5RjY3IiwidmlzaXRvcl9pZCI6IjIzNDc2NTQ5Mjk5MjYxNjg0MjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c0795f6034e79f3c5779c6ca4c807fe1f421d5601e6f7b5bff21b70301eac1e5 |
| hovercard-subject-tag | issue:2772031135 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/2541/issue_layout |
| twitter:image | https://opengraph.githubassets.com/25fae9c350a56b693f38c8b0d025a794aea1ed930531e3867dd847ee5368e436/pythonnet/pythonnet/issues/2541 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/25fae9c350a56b693f38c8b0d025a794aea1ed930531e3867dd847ee5368e436/pythonnet/pythonnet/issues/2541 |
| og:image:alt | 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 sa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | YogesGovindaraj |
| hostname | github.com |
| expected-hostname | github.com |
| None | fdfdce9cd4f6ab85dca2b0d11264270829297c962dd5a79df449062d7822258f |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 51c736e60b302bd039c9d5164573d176ceb24bb2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width