Closed DrEricEbert closed 2 years ago
First check the Numpy.NET readme what I wrote about avoiding deadlocks. https://github.com/SciSharp/Numpy.NET#multi-threading-must-read
If that doesn't help I think you need to download the source code and step into it with the debugger to find out why it never returns.
Ok i've tried out both suggestions.
PythonEngine.BeginAllowThreads()
and
using (Py.GIL())
{
...
}
Are working after the Interpreter is Running. I got
System.AggregateException
HResult=0x80131500
Nachricht = Mindestens ein Fehler ist aufgetreten.
Quelle = mscorlib
Stapelüberwachung:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at PythonRunnerUI.PythonRunnerUIForm.runToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Data\HyDesign\trunk\Code\PythonNetTester\PythonRunnerUI\PythonRunnerUIForm.cs:line 28
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.MenuStrip.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at PythonRunnerUI.Program.Main() in C:\Data\HyDesign\trunk\Code\PythonNetTester\PythonRunnerUI\Program.cs:line 19
Innere Ausnahme 1:
DllNotFoundException: Die DLL "python37": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.
on PythonEngine.BeginAllowThreads() and
System.AggregateException
HResult=0x80131500
Nachricht = Mindestens ein Fehler ist aufgetreten.
Quelle = mscorlib
Stapelüberwachung:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at PythonRunnerUI.PythonRunnerUIForm.runToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Data\HyDesign\trunk\Code\PythonNetTester\PythonRunnerUI\PythonRunnerUIForm.cs:line 28
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.MenuStrip.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at PythonRunnerUI.Program.Main() in C:\Data\HyDesign\trunk\Code\PythonNetTester\PythonRunnerUI\Program.cs:line 19
Innere Ausnahme 1:
DllNotFoundException: Die DLL "python37": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.
on the using Py.GIL() statement... Without it works in console application.
I've stepped into the Libs...
The Code stopped at:
public static async Task SetupPython(bool force = false)
{
Environment.SetEnvironmentVariable("PATH", $"{EmbeddedPythonHome};" + Environment.GetEnvironmentVariable("PATH"));
if (!force && Directory.Exists(EmbeddedPythonHome) && File.Exists(Path.Combine(EmbeddedPythonHome, "python.exe"))) // python seems installed, so exit
return;
var zip = await Source.RetrievePythonZip(InstallPath);
Could this be the reason? https://stackoverflow.com/questions/13140523/await-vs-task-wait-deadlock
This works:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PythonRunnerUI
{
public partial class PythonRunnerUIForm : Form
{
public PythonRunnerUIForm()
{
InitializeComponent();
}
private void beendenToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void runToolStripMenuItem_Click(object sender, EventArgs e)
{
Task.Run(()=>
{
PythonRunnnerCL.PythonRunnerClass.Runner();
});
}
}
}
I have written a .Net 4.7.2 Class Library and installed the Python.Included 3.7.3.13 Nugget with the following code:
The DLL works fine for a Console Application with this Code:
But not for a WindowsForms Application with the following code:
Why actually? It uses the same .Net framework base... The code downloads the python-3.7.3-embed-amd64.zip as expected and stops in Installer.SetupPython().Wait(); after loading the embedded python distribution. Does anyone have an idea?