I am using pythonnet in a c#-application successfully. Now I am trying to call pythonnet code from a parallel.for loop.
The regular for-loop works fine but not when parallel is used. The programm is not responding and not showing an error message.
(I tried different ways to do this as well including calling the Py.GIL explicitly and using threading. But couldnt get it to run)
Here is a simplified version of my code:
static void Main(string[] args)
{
PythonEngine.Initialize();
dynamic np = PythonEngine.ImportModule("numpy");
dynamic[] Output = new dynamic[10];
dynamic[] Output2 = new dynamic[10];
for (int i = 0; i < 10; i++)
{
Output[i] = np.cos(np.pi * i);
}
Parallel.For(0, 10, i =>
{
Output2[i] = np.cos(np.pi * 2);
});
Console.ReadLine();
}