问题描述:NET multi-threaded execution Python method, in Py. GIL can not run
解决方案:https://github.com/pythonnet/pythonnet/issues/109
具体解决步骤,下载pythonnet-master,解压后打开pythonnet.sln,点击Python.Runtime项目目录下的pythonengine.cs,按照以上网站修改代码,在Python.Runtime项目下生成dll文件。
以下为引用pythonnet生成的dll文件的测试多线程的简单代码
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Python.Runtime;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Threading;
namespace MultithreadingApplication
{
class ThreadCreationProgram
{
public static void CallToChildThread()
{
using (Py.GIL())
{
Console.WriteLine("1");
}
Console.WriteLine("2