Any chance you can share what the source is? The exception comes from PythonCopyReg's initialization, which means we might have a bug (it might not be thread-safe, or something else). If you could create a minimal sample that has the issue that would be even better.<div>
<br></div><div>- Jeff<br><br><div class="gmail_quote">On Thu, Apr 14, 2011 at 9:18 PM, surangika ranathunga <span dir="ltr"><<a href="mailto:lady_radsu@yahoo.com">lady_radsu@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit">Hi,<br>Below is the exception I receive:<br>here, D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88 refers to source.Execute(scope); in the below given code.<br>
<br>System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceExce<br>
ption: Object reference not set to an instance of an object.<br> at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)<br> at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)<br>
at IronPython.Runtime.PythonContext.GetEqualSite(Type type)<br> at
IronPython.Runtime.CommonDictionaryStorage.UpdateHelperFunctions(Type t, Object key)<br> at IronPython.Runtime.CommonDictionaryStorage.AddNoLock(Object key, Object value)<br> at IronPython.Runtime.CommonDictionaryStorage.Add(Object key, Object value)<br>
at IronPython.Runtime.PythonDictionary.SetItem(Object key, Object value)<br> at IronPython.Runtime.PythonDictionary.set_Item(Object key, Object value)<br> at IronPython.Modules.PythonCopyReg.PerformModuleReload(PythonContext context, PythonDictionary dict)<br>
--- End of inner exception stack trace ---<br> at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)<br>
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments,
Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)<br> at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)<br>
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)<br> at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)<br>
at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type, ModuleOptions options)<br> at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type)<br> at IronPython.Runtime.PythonContext.CreateBuiltinModule(String name)<br>
at IronPython.Runtime.PythonContext.GetBuiltinModule(String name)<br> at
IronPython.Runtime.Importer.ImportBuiltin(CodeContext context, String name)<br> at IronPython.Modules.PythonCopyReg.EnsureModuleInitialized(CodeContext context)<br> at IronPython.Modules.PythonCopyReg.GetDispatchTable(CodeContext context)<br>
at IronPython.Modules.PythonRegex.PerformModuleReload(PythonContext context,PythonDictionary dict)<br> --- End of inner exception stack trace ---<br> at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[] args, Boolean& shouldOptimize)<br>
at IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`5.Call4(CallSite site, CodeContext context, TFuncType func, T0 arg0, T1 arg1, T2 arg2, T3 arg3)<br> at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)<br>
at IronPython.Runtime.Importer.Import(CodeContext
context, String fullName, PythonTuple from, Int32 level)<br> at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)<br> at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)<br>
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)<br> at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)<br> at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)<br>
at IronPython.Compiler.PythonScriptCode.Run(Scope scope)<br> at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)<br> at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)<br> at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)<br>
at Microsoft.Scripting.SourceUnit.Execute(Scope scope)<br> at
Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)<br> at MonitorService.ExpectationMonitor.Initialize(String rule) in D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88<br>
<br>--- On <b>Thu, 14/4/11, Jeff Hardy <i><<a href="mailto:jdhardy@gmail.com" target="_blank">jdhardy@gmail.com</a>></i></b> wrote:<br><blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px">
<br>From: Jeff Hardy <<a href="mailto:jdhardy@gmail.com" target="_blank">jdhardy@gmail.com</a>><br>Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?<br>To: "Discussion of IronPython" <<a href="mailto:users@lists.ironpython.com" target="_blank">users@lists.ironpython.com</a>><br>
Cc: "surangika ranathunga" <<a href="mailto:lady_radsu@yahoo.com" target="_blank">lady_radsu@yahoo.com</a>><br>Received: Thursday, 14 April, 2011, 7:35 AM<div><div></div><div class="h5"><br><br><div>As long as you have a ScriptScope per thread, you should be able to<br>
share the ScriptEngine & Runtime between threads.<br><br>What is the exception that you are getting? If it's a GUI
program,<br>remember that UI elements can only be manipulated from the main<br>thread.<br><br>- Jeff<br><br>On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga<br><<a href="http://mc/compose?to=lady_radsu@yahoo.com" target="_blank">lady_radsu@yahoo.com</a>> wrote:<br>
><br>> Hi,<br>> I am using Ironpython to connect to a legacy python code from C#.<br>> I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.<br>> This is how I implemented this:<br>
><br>> ScriptEngine engine = Python.CreateEngine();<br>> ScriptRuntime runtime = engine.Runtime;<br>> ScriptScope scope =
runtime.CreateScope();<br>> ops = engine.Operations;<br>> ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");<br>> source.Execute(scope);<br>
> string class_param = rule;<br>> object[] parameters = new object[1];<br>> parameters[0] = class_param;<br>> object klass =
scope.GetVariable("model_checker");<br>> object instance = ops.Invoke(klass, parameters);<br>> method = ops.GetMember(instance, "check_model");<br>><br>> Now I want to make my application multi-threaded, and I want to have concurrently running scripting engines. Essentially, these engines should access the same underlying python code, and hence these scripting engines are identical to each other.<br>
> Without any change, the above code works fine for most of the time for a multi-threaded application. However, there is an exception that appears from time to time, and I suspect that it is due to a concurrency issue.<br>
><br>> Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering
with each other?<br>><br>> any ideas greatly appreciated<br>><br>> _______________________________________________<br>> Users mailing list<br>> <a href="http://mc/compose?to=Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
> <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>><br></div></div></div></blockquote></td></tr></tbody></table>
</blockquote></div><br></div>