[Ironpython-users] System.InsufficientMemoryException when calling a python method

surangika ranathunga lady_radsu at yahoo.com
Wed Mar 28 00:50:44 CEST 2012


Hi All,
I am using Ironpython to call a python method from my C# class. 

This is how i call the python method.

 ScriptScope scope = runtime.CreateScope();
ops = engine.Operations;

 ScriptSource source = engine.CreateScriptSourceFromFile("nlp.py");
source.Execute(scope);
 object klass = scope.GetVariable("nlp");
object instance = ops.Invoke(klass);
method = ops.GetMember(instance, "identify_dtag");

object[] parameters = new object[1];
parameters[0] = line;
object output = ops.Invoke(method, parameters);
return output.ToString(); 

Error occurs atobject output = ops.Invoke(method, parameters);  line.


In this python method, I am calling a method in the NLTK toolkit.

System configurations: Ironpython 2.7, python 2.6, C# 4.0


This is called in a threaded environment. However, currently only one thread is active.

Hope someone can help me out.

Here is the stack trace:

System.InsufficientMemoryException: Exception of type 'System.InsufficientMemory
Exception' was thrown.
   at NumpyDotNet.NpyCoreApi.CheckError()
   at NumpyDotNet.NpyCoreApi.DescrFromType(NPY_TYPES type)
   at NumpyDotNet.NpyDescr.ConvertSimpleString(CodeContext cntx, String s, Byteendian)
   at NumpyDotNet.NpyDescr.ConvertSimpleString(CodeContext cntx, String s)
   at NumpyDotNet.NpyDescr.DescrConverter(CodeContext cntx, Object obj, Booleanalign)
   at NumpyDotNet.ndarray.Construct(CodeContext cntx, Object shape, Object dtype, Object buffer, Object offset, Object strides, Object order)
   at NumpyDotNet.ndarray.__new__(CodeContext cntx, PythonType cls, Object shape, Object dtype, Object buffer, Object offset, Object strides, Object order)
   at NumpyDotNet.ModuleMethods._reconstruct(CodeContext cntx, PythonType subtype, Object shape, Object dtype)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at CallSite.Target(Closure , CallSite , CodeContext , Object , Object[] )
   at IronPython.Runtime.PythonContext.CallSplat(Object func, Object[] args)
   at IronPython.Modules.PythonPickle.UnpicklerObject.LoadReduce(CodeContext context)
   at IronPython.Modules.PythonPickle.UnpicklerObject.load(CodeContext context)
   at IronPython.Modules.PythonPickle.load(CodeContext context, Object file)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at IronPython.Runtime.PythonFunction.FunctionCaller`1.Call1(CallSite site, CodeContext context, Object func, T0 arg0)
   at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
   at IronPython.Compiler.PythonCallTargets.OriginalCallTarget6(PythonFunction function, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object
 arg5)
   at IronPython.Runtime.PythonFunction.FunctionCaller`1.Default5Call1(CallSitesite, CodeContext context, Object func, T0 arg0)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at IronPython.Runtime.Method.MethodBinding`1.SelfTarget(CallSite site, CodeContext context, Object target, T0 arg0)
   at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronPython.Compiler.PythonCallTargets.OriginalCallTarget1(PythonFunction function, Object arg0)
   at IronPython.Runtime.PythonFunction.FunctionCaller`1.Call1(CallSite site, CodeContext context, Object func, T0 arg0)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrameframe)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
   at IronPython.Compiler.PythonCallTargets.OriginalCallTarget2(PythonFunction function, Object arg0, Object arg1)
   at IronPython.Runtime.PythonFunction.FunctionCaller`2.Call2(CallSite site, CodeContext context, Object func, T0 arg0, T1 arg1)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at CallSite.Target(Closure , CallSite , Object , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at lambda_method(Closure , DynamicOperations , CallSiteBinder , Object , Object[] )
   at Microsoft.Scripting.Runtime.DynamicOperations.Invoke(Object obj, Object[]parameters)
   at Microsoft.Scripting.Hosting.ObjectOperations.Invoke(Object obj, Object[] parameters)
   at SL_LIBOMV_Connector.DtagGenerator.IdentifyDtag(String line) in D:\PhD Work\Research\libomv\test\SL_LIBOMV_Connector OVH-NLP\SL_LIBOMV_Connector\DtagGenera
tor.cs:line 67
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20120327/b10b1539/attachment.html>


More information about the Ironpython-users mailing list