embed Python in C#

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

embed Python in C#

igorfier
Hello all,
 
After following some examples around the web, and some discussions in the mail list,
I came into the following snippet to call a function defined in a Python script into a C# host app,
 
//
public static void MethodThatCallsPython()
        {
            // have to acquire the GIL to safely call back into Python!!
            IntPtr state = PythonEngine.AcquireLock();
 
            PythonEngine.RunSimpleString("print 'hello'");
 
            // done using python for now, so release the GIL...
            PythonEngine.ReleaseLock(state);
        }
//
 
Although it looks quite simple, VS2010 this throws an exception at the very first line of code:
“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”
 
My machine runs Windows 7 64-bit, and as I read somewhere else, 64 bit OS may be a matter of concern.
Does anyone know how to overcome this annoying situation??
 
Thank you for any help provided!
 
Igor Fier
Dept. of Physics, Condensed Matter
UNESP Rio Claro – Rio Claro-SP, Brazil

_________________________________________________
Python.NET mailing list - [hidden email]
http://mail.python.org/mailman/listinfo/pythondotnet
Reply | Threaded
Open this post in threaded view
|

Re: embed Python in C#

Brian Lloyd-7
Re: [Python.NET] embed Python in C# Python for .NET has a huge amount of carnal knowledge about the in-memory
layouts of python objects etc., and I don’t know that anyone has tried to port
it run with 64-bit :(


On 8/16/10 1:08 PM, "[hidden email]" <[hidden email]> wrote:

Hello all,
 
After following some examples around the web, and some discussions in the mail list,
I came into the following snippet to call a function defined in a Python script into a C# host app,
as seen at “http://mail.python.org/pipermail/pythondotnet/2007-June/000620.html”:
 
//
public static void MethodThatCallsPython()
        {
            // have to acquire the GIL to safely call back into Python!!
            IntPtr state = PythonEngine.AcquireLock();
 
            PythonEngine.RunSimpleString("print 'hello'");
 
            // done using python for now, so release the GIL...
            PythonEngine.ReleaseLock(state);
        }
//
 
Although it looks quite simple, VS2010 this throws an exception at the very first line of code:
“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”
 
My machine runs Windows 7 64-bit, and as I read somewhere else, 64 bit OS may be a matter of concern.
Does anyone know how to overcome this annoying situation??
 
Thank you for any help provided!
 
Igor Fier
Dept. of Physics, Condensed Matter
UNESP Rio Claro – Rio Claro-SP, Brazil


_________________________________________________
Python.NET mailing list - [hidden email]
http://mail.python.org/mailman/listinfo/pythondotnet


--------------------------
Brian Lloyd   540.845.2975

[hidden email]

_________________________________________________
Python.NET mailing list - [hidden email]
http://mail.python.org/mailman/listinfo/pythondotnet