-
Notifications
You must be signed in to change notification settings - Fork 763
Closed
Description
Environment
Environment
Pythonnet version: Runtime Version v4.0.30319
Python version: conda (3.7)
Operating System: Windows 10
.NET Runtime: 4.6.1
Details
Hello, I need to run a python file multiple times . I have a server - client interface where multiple client should be able to execute run a python file. one after the other.
In the below code:
I try to execute a python file two times. I notice that the first time it runs perfectly but for the second time it throws an AccessViolationException
saying it Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
class Program
{
static void Main(string[] args)
{
for (int i = 0; i <= 2; i++)
{
connectPython();
i += 1;
}
Console.ReadKey();
}
static void connectPython()
{
IPythonConnector python = new PythonConnector();
python.EstablishConnection();
try
{
dynamic mainFile;
using (Py.GIL())
{
mainFile = Py.Import("main");
}
dynamic running = mainFile.main();
}
finally
{
PythonEngine.Shutdown();
}
}
Metadata
Metadata
Assignees
Labels
No labels