how to generate multiple concurrent scriptign engines?

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

how to generate multiple concurrent scriptign engines?

suralk
Hi,
I am using Ironpython to connect to a legacy python code from C#.
I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.
This is how I implemented this:

                ScriptEngine engine = Python.CreateEngine();
                ScriptRuntime runtime = engine.Runtime;
                ScriptScope scope = runtime.CreateScope();
                ops = engine.Operations;
                ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
                source.Execute(scope);
                string class_param = rule;
                object[] parameters = new object[1];
                parameters[0] = class_param;
                object klass = scope.GetVariable("model_checker");
                object instance = ops.Invoke(klass, parameters);
                method = ops.GetMember(instance, "check_model");

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.
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.

Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering with each other?

any ideas greatly appreciated

_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: how to generate multiple concurrent scriptign engines?

Jeff Hardy-4
As long as you have a ScriptScope per thread, you should be able to
share the ScriptEngine & Runtime between threads.

What is the exception that you are getting? If it's a GUI program,
remember that UI elements can only be manipulated from the main
thread.

- Jeff

On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga
<[hidden email]> wrote:

>
> Hi,
> I am using Ironpython to connect to a legacy python code from C#.
> I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.
> This is how I implemented this:
>
>                 ScriptEngine engine = Python.CreateEngine();
>                 ScriptRuntime runtime = engine.Runtime;
>                 ScriptScope scope = runtime.CreateScope();
>                 ops = engine.Operations;
>                 ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
>                 source.Execute(scope);
>                 string class_param = rule;
>                 object[] parameters = new object[1];
>                 parameters[0] = class_param;
>                 object klass = scope.GetVariable("model_checker");
>                 object instance = ops.Invoke(klass, parameters);
>                 method = ops.GetMember(instance, "check_model");
>
> 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.
> 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.
>
> Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering with each other?
>
> any ideas greatly appreciated
>
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: how to generate multiple concurrent scriptign engines?

suralk
Hi,
Below is the exception I receive:
here, D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88 refers to source.Execute(scope); in the below given code.

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
ption: Object reference not set to an instance of an object.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
   at IronPython.Runtime.PythonContext.GetEqualSite(Type type)
   at IronPython.Runtime.CommonDictionaryStorage.UpdateHelperFunctions(Type t, Object key)
   at IronPython.Runtime.CommonDictionaryStorage.AddNoLock(Object key, Object value)
   at IronPython.Runtime.CommonDictionaryStorage.Add(Object key, Object value)
   at IronPython.Runtime.PythonDictionary.SetItem(Object key, Object value)
   at IronPython.Runtime.PythonDictionary.set_Item(Object key, Object value)
   at IronPython.Modules.PythonCopyReg.PerformModuleReload(PythonContext context, PythonDictionary dict)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type, ModuleOptions options)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String name)
   at IronPython.Runtime.PythonContext.GetBuiltinModule(String name)
   at IronPython.Runtime.Importer.ImportBuiltin(CodeContext context, String name)
   at IronPython.Modules.PythonCopyReg.EnsureModuleInitialized(CodeContext context)
   at IronPython.Modules.PythonCopyReg.GetDispatchTable(CodeContext context)
   at IronPython.Modules.PythonRegex.PerformModuleReload(PythonContext context,PythonDictionary dict)
   --- End of inner exception stack trace ---
   at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[] args, Boolean& shouldOptimize)
   at IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`5.Call4(CallSite site, CodeContext context, TFuncType func, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   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)
   at IronPython.Runtime.Importer.Import(CodeContext context, String fullName, PythonTuple from, Int32 level)
   at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.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.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
   at MonitorService.ExpectationMonitor.Initialize(String rule) in D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88

--- On Thu, 14/4/11, Jeff Hardy <[hidden email]> wrote:

From: Jeff Hardy <[hidden email]>
Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?
To: "Discussion of IronPython" <[hidden email]>
Cc: "surangika ranathunga" <[hidden email]>
Received: Thursday, 14 April, 2011, 7:35 AM

As long as you have a ScriptScope per thread, you should be able to
share the ScriptEngine & Runtime between threads.

What is the exception that you are getting? If it's a GUI program,
remember that UI elements can only be manipulated from the main
thread.

- Jeff

On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga
<lady_radsu@...> wrote:

>
> Hi,
> I am using Ironpython to connect to a legacy python code from C#.
> I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.
> This is how I implemented this:
>
>                 ScriptEngine engine = Python.CreateEngine();
>                 ScriptRuntime runtime = engine.Runtime;
>                 ScriptScope scope = runtime.CreateScope();
>                 ops = engine.Operations;
>                 ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
>                 source.Execute(scope);
>                 string class_param = rule;
>                 object[] parameters = new object[1];
>                 parameters[0] = class_param;
>                 object klass = scope.GetVariable("model_checker");
>                 object instance = ops.Invoke(klass, parameters);
>                 method = ops.GetMember(instance, "check_model");
>
> 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.
> 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.
>
> Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering with each other?
>
> any ideas greatly appreciated
>
> _______________________________________________
> Users mailing list
> Users@...
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>

_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: how to generate multiple concurrent scriptign engines?

Jeff Hardy-4
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.

- Jeff

On Thu, Apr 14, 2011 at 9:18 PM, surangika ranathunga <[hidden email]> wrote:
Hi,
Below is the exception I receive:
here, D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88 refers to source.Execute(scope); in the below given code.

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
ption: Object reference not set to an instance of an object.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
   at IronPython.Runtime.PythonContext.GetEqualSite(Type type)
   at IronPython.Runtime.CommonDictionaryStorage.UpdateHelperFunctions(Type t, Object key)
   at IronPython.Runtime.CommonDictionaryStorage.AddNoLock(Object key, Object value)
   at IronPython.Runtime.CommonDictionaryStorage.Add(Object key, Object value)
   at IronPython.Runtime.PythonDictionary.SetItem(Object key, Object value)
   at IronPython.Runtime.PythonDictionary.set_Item(Object key, Object value)
   at IronPython.Modules.PythonCopyReg.PerformModuleReload(PythonContext context, PythonDictionary dict)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type, ModuleOptions options)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String name)
   at IronPython.Runtime.PythonContext.GetBuiltinModule(String name)
   at IronPython.Runtime.Importer.ImportBuiltin(CodeContext context, String name)
   at IronPython.Modules.PythonCopyReg.EnsureModuleInitialized(CodeContext context)
   at IronPython.Modules.PythonCopyReg.GetDispatchTable(CodeContext context)
   at IronPython.Modules.PythonRegex.PerformModuleReload(PythonContext context,PythonDictionary dict)
   --- End of inner exception stack trace ---
   at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[] args, Boolean& shouldOptimize)
   at IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`5.Call4(CallSite site, CodeContext context, TFuncType func, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   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)
   at IronPython.Runtime.Importer.Import(CodeContext context, String fullName, PythonTuple from, Int32 level)
   at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.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.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
   at MonitorService.ExpectationMonitor.Initialize(String rule) in D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88

--- On Thu, 14/4/11, Jeff Hardy <[hidden email]> wrote:

From: Jeff Hardy <[hidden email]>
Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?
To: "Discussion of IronPython" <[hidden email]>
Cc: "surangika ranathunga" <[hidden email]>
Received: Thursday, 14 April, 2011, 7:35 AM


As long as you have a ScriptScope per thread, you should be able to
share the ScriptEngine & Runtime between threads.

What is the exception that you are getting? If it's a GUI program,
remember that UI elements can only be manipulated from the main
thread.

- Jeff

On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga
<lady_radsu@...> wrote:
>
> Hi,
> I am using Ironpython to connect to a legacy python code from C#.
> I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.
> This is how I implemented this:
>
>                 ScriptEngine engine = Python.CreateEngine();
>                 ScriptRuntime runtime = engine.Runtime;
>                 ScriptScope scope = runtime.CreateScope();
>                 ops = engine.Operations;
>                 ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
>                 source.Execute(scope);
>                 string class_param = rule;
>                 object[] parameters = new object[1];
>                 parameters[0] = class_param;
>                 object klass = scope.GetVariable("model_checker");
>                 object instance = ops.Invoke(klass, parameters);
>                 method = ops.GetMember(instance, "check_model");
>
> 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.
> 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.
>
> Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering with each other?
>
> any ideas greatly appreciated
>
> _______________________________________________
> Users mailing list
> Users@...
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>


_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

WPF module in IronPython scripting?

Lukáš Duběda
Hi there everyone,

I just bumped into a problem where when I run the IPy.exe console
and execute a script that contains:

import wpf

all works well. However, when I want to import the wpf namespace into
the same script, but run outside the IPy.exe (i.e. as an embedded engine)
I get an error saying that the module wpf doesn't exist!

I even tried to add the IronPython.Wpf.dll into the PATH,
I tried referencing it in my script via clr.AddReferenceToFile,
nothing works and I don't have access to the wpf methods etc...

Is there anything I can do about it?

As always, thanks a lot in advance! :)

Lukáš Duběda
Director
[T] +420 602 444 164

duber studio(tm)
[M] [hidden email]
[W] http://www.duber.cz

[A] R.A.Dvorského 601, Praha 10
[A] 10900, Czech Republic, Europe
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: how to generate multiple concurrent scriptign engines?

Dino Viehland
In reply to this post by Jeff Hardy-4

It might come from CopyReg but the bug is definitely in GetEqualSite – we just need a lock(_equalSites) { … } around the TryGetValue and creation of the equal site.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Jeff Hardy
Sent: Friday, April 15, 2011 7:29 AM
To: surangika ranathunga
Cc: Discussion of IronPython
Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?

 

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.

 

- Jeff

On Thu, Apr 14, 2011 at 9:18 PM, surangika ranathunga <[hidden email]> wrote:

Hi,
Below is the exception I receive:
here, D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88 refers to source.Execute(scope); in the below given code.

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
ption: Object reference not set to an instance of an object.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
   at IronPython.Runtime.PythonContext.GetEqualSite(Type type)
   at IronPython.Runtime.CommonDictionaryStorage.UpdateHelperFunctions(Type t, Object key)
   at IronPython.Runtime.CommonDictionaryStorage.AddNoLock(Object key, Object value)
   at IronPython.Runtime.CommonDictionaryStorage.Add(Object key, Object value)
   at IronPython.Runtime.PythonDictionary.SetItem(Object key, Object value)
   at IronPython.Runtime.PythonDictionary.set_Item(Object key, Object value)
   at IronPython.Modules.PythonCopyReg.PerformModuleReload(PythonContext context, PythonDictionary dict)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type, ModuleOptions options)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String name)
   at IronPython.Runtime.PythonContext.GetBuiltinModule(String name)
   at IronPython.Runtime.Importer.ImportBuiltin(CodeContext context, String name)
   at IronPython.Modules.PythonCopyReg.EnsureModuleInitialized(CodeContext context)
   at IronPython.Modules.PythonCopyReg.GetDispatchTable(CodeContext context)
   at IronPython.Modules.PythonRegex.PerformModuleReload(PythonContext context,PythonDictionary dict)
   --- End of inner exception stack trace ---
   at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[] args, Boolean& shouldOptimize)
   at IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`5.Call4(CallSite site, CodeContext context, TFuncType func, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   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)
   at IronPython.Runtime.Importer.Import(CodeContext context, String fullName, PythonTuple from, Int32 level)
   at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.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.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
   at MonitorService.ExpectationMonitor.Initialize(String rule) in D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88

--- On Thu, 14/4/11, Jeff Hardy <[hidden email]> wrote:


From: Jeff Hardy <[hidden email]>
Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?
To: "Discussion of IronPython" <[hidden email]>
Cc: "surangika ranathunga" <[hidden email]>
Received: Thursday, 14 April, 2011, 7:35 AM

 

As long as you have a ScriptScope per thread, you should be able to
share the ScriptEngine & Runtime between threads.

What is the exception that you are getting? If it's a GUI program,
remember that UI elements can only be manipulated from the main
thread.

- Jeff

On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga
<lady_radsu@...> wrote:
>
> Hi,
> I am using Ironpython to connect to a legacy python code from C#.
> I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.
> This is how I implemented this:
>
>                 ScriptEngine engine = Python.CreateEngine();
>                 ScriptRuntime runtime = engine.Runtime;
>                 ScriptScope scope = runtime.CreateScope();
>                 ops = engine.Operations;
>                 ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
>                 source.Execute(scope);
>                 string class_param = rule;
>                 object[] parameters = new object[1];
>                 parameters[0] = class_param;
>                 object klass = scope.GetVariable("model_checker");
>                 object instance = ops.Invoke(klass, parameters);
>                 method = ops.GetMember(instance, "check_model");
>
> 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.
> 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.
>
> Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering with each other?
>
> any ideas greatly appreciated
>
> _______________________________________________
> Users mailing list
> Users@...
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>

 


_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: WPF module in IronPython scripting?

Dino Viehland
In reply to this post by Lukáš Duběda
Lukáš wrote:

> Hi there everyone,
>
> I just bumped into a problem where when I run the IPy.exe console and
> execute a script that contains:
>
> import wpf
>
> all works well. However, when I want to import the wpf namespace into the
> same script, but run outside the IPy.exe (i.e. as an embedded engine) I get
> an error saying that the module wpf doesn't exist!
>
> I even tried to add the IronPython.Wpf.dll into the PATH, I tried referencing
> it in my script via clr.AddReferenceToFile, nothing works and I don't have
> access to the wpf methods etc...
>
> Is there anything I can do about it?

I would have expected AddReferenceToFile to work but what about doing a
scriptRuntime.LoadAssembly(typeof(Wpf).Assembly);  where the host app
has a reference to IronPython.Wpf.dll?  

I think the code for loading from the DLLs directory is ipy.exe specific - you could
also look at replicating that for your host app so there's a general way to add
additional Python built-in modules.


_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: how to generate multiple concurrent scriptign engines?

Jeff Hardy-4
In reply to this post by Dino Viehland
Can one of your alter-egos file a bug so it doesn't get lost?

- Jeff

On Fri, Apr 15, 2011 at 10:36 AM, Dino Viehland <[hidden email]> wrote:

It might come from CopyReg but the bug is definitely in GetEqualSite – we just need a lock(_equalSites) { … } around the TryGetValue and creation of the equal site.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Jeff Hardy
Sent: Friday, April 15, 2011 7:29 AM
To: surangika ranathunga
Cc: Discussion of IronPython


Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?

 

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.

 

- Jeff

On Thu, Apr 14, 2011 at 9:18 PM, surangika ranathunga <[hidden email]> wrote:

Hi,
Below is the exception I receive:
here, D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88 refers to source.Execute(scope); in the below given code.

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
ption: Object reference not set to an instance of an object.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
   at IronPython.Runtime.PythonContext.GetEqualSite(Type type)
   at IronPython.Runtime.CommonDictionaryStorage.UpdateHelperFunctions(Type t, Object key)
   at IronPython.Runtime.CommonDictionaryStorage.AddNoLock(Object key, Object value)
   at IronPython.Runtime.CommonDictionaryStorage.Add(Object key, Object value)
   at IronPython.Runtime.PythonDictionary.SetItem(Object key, Object value)
   at IronPython.Runtime.PythonDictionary.set_Item(Object key, Object value)
   at IronPython.Modules.PythonCopyReg.PerformModuleReload(PythonContext context, PythonDictionary dict)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type, ModuleOptions options)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String name)
   at IronPython.Runtime.PythonContext.GetBuiltinModule(String name)
   at IronPython.Runtime.Importer.ImportBuiltin(CodeContext context, String name)
   at IronPython.Modules.PythonCopyReg.EnsureModuleInitialized(CodeContext context)
   at IronPython.Modules.PythonCopyReg.GetDispatchTable(CodeContext context)
   at IronPython.Modules.PythonRegex.PerformModuleReload(PythonContext context,PythonDictionary dict)
   --- End of inner exception stack trace ---
   at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[] args, Boolean& shouldOptimize)
   at IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`5.Call4(CallSite site, CodeContext context, TFuncType func, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   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)
   at IronPython.Runtime.Importer.Import(CodeContext context, String fullName, PythonTuple from, Int32 level)
   at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.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.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
   at MonitorService.ExpectationMonitor.Initialize(String rule) in D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88

--- On Thu, 14/4/11, Jeff Hardy <[hidden email]> wrote:


From: Jeff Hardy <[hidden email]>
Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?
To: "Discussion of IronPython" <[hidden email]>
Cc: "surangika ranathunga" <[hidden email]>
Received: Thursday, 14 April, 2011, 7:35 AM

 

As long as you have a ScriptScope per thread, you should be able to
share the ScriptEngine & Runtime between threads.

What is the exception that you are getting? If it's a GUI program,
remember that UI elements can only be manipulated from the main
thread.

- Jeff

On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga
<lady_radsu@...> wrote:
>
> Hi,
> I am using Ironpython to connect to a legacy python code from C#.
> I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.
> This is how I implemented this:
>
>                 ScriptEngine engine = Python.CreateEngine();
>                 ScriptRuntime runtime = engine.Runtime;
>                 ScriptScope scope = runtime.CreateScope();
>                 ops = engine.Operations;
>                 ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
>                 source.Execute(scope);
>                 string class_param = rule;
>                 object[] parameters = new object[1];
>                 parameters[0] = class_param;
>                 object klass = scope.GetVariable("model_checker");
>                 object instance = ops.Invoke(klass, parameters);
>                 method = ops.GetMember(instance, "check_model");
>
> 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.
> 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.
>
> Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering with each other?
>
> any ideas greatly appreciated
>
> _______________________________________________
> Users mailing list
> Users@...
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>

 


_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: how to generate multiple concurrent scriptign engines?

Dino Viehland

Filed as http://ironpython.codeplex.com/workitem/30551

 

From: Jeff Hardy [mailto:[hidden email]]
Sent: Friday, April 15, 2011 9:41 AM
To: Discussion of IronPython
Cc: Dino Viehland; surangika ranathunga
Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?

 

Can one of your alter-egos file a bug so it doesn't get lost?

 

- Jeff

On Fri, Apr 15, 2011 at 10:36 AM, Dino Viehland <[hidden email]> wrote:

It might come from CopyReg but the bug is definitely in GetEqualSite – we just need a lock(_equalSites) { … } around the TryGetValue and creation of the equal site.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Jeff Hardy
Sent: Friday, April 15, 2011 7:29 AM
To: surangika ranathunga
Cc: Discussion of IronPython


Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?

 

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.

 

- Jeff

On Thu, Apr 14, 2011 at 9:18 PM, surangika ranathunga <[hidden email]> wrote:

Hi,
Below is the exception I receive:
here, D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88 refers to source.Execute(scope); in the below given code.

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
ption: Object reference not set to an instance of an object.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
   at IronPython.Runtime.PythonContext.GetEqualSite(Type type)
   at IronPython.Runtime.CommonDictionaryStorage.UpdateHelperFunctions(Type t, Object key)
   at IronPython.Runtime.CommonDictionaryStorage.AddNoLock(Object key, Object value)
   at IronPython.Runtime.CommonDictionaryStorage.Add(Object key, Object value)
   at IronPython.Runtime.PythonDictionary.SetItem(Object key, Object value)
   at IronPython.Runtime.PythonDictionary.set_Item(Object key, Object value)
   at IronPython.Modules.PythonCopyReg.PerformModuleReload(PythonContext context, PythonDictionary dict)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type, ModuleOptions options)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String moduleName, Type type)
   at IronPython.Runtime.PythonContext.CreateBuiltinModule(String name)
   at IronPython.Runtime.PythonContext.GetBuiltinModule(String name)
   at IronPython.Runtime.Importer.ImportBuiltin(CodeContext context, String name)
   at IronPython.Modules.PythonCopyReg.EnsureModuleInitialized(CodeContext context)
   at IronPython.Modules.PythonCopyReg.GetDispatchTable(CodeContext context)
   at IronPython.Modules.PythonRegex.PerformModuleReload(PythonContext context,PythonDictionary dict)
   --- End of inner exception stack trace ---
   at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[] args, Boolean& shouldOptimize)
   at IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`5.Call4(CallSite site, CodeContext context, TFuncType func, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   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)
   at IronPython.Runtime.Importer.Import(CodeContext context, String fullName, PythonTuple from, Int32 level)
   at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.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.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
   at MonitorService.ExpectationMonitor.Initialize(String rule) in D:\PhD Work\Research\libomv\test\MonitorService\MonitorService\ExpectationMonitor.cs:line 88

--- On Thu, 14/4/11, Jeff Hardy <[hidden email]> wrote:


From: Jeff Hardy <[hidden email]>
Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?
To: "Discussion of IronPython" <[hidden email]>
Cc: "surangika ranathunga" <[hidden email]>
Received: Thursday, 14 April, 2011, 7:35 AM

 

As long as you have a ScriptScope per thread, you should be able to
share the ScriptEngine & Runtime between threads.

What is the exception that you are getting? If it's a GUI program,
remember that UI elements can only be manipulated from the main
thread.

- Jeff

On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga
<lady_radsu@...> wrote:
>
> Hi,
> I am using Ironpython to connect to a legacy python code from C#.
> I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.
> This is how I implemented this:
>
>                 ScriptEngine engine = Python.CreateEngine();
>                 ScriptRuntime runtime = engine.Runtime;
>                 ScriptScope scope = runtime.CreateScope();
>                 ops = engine.Operations;
>                 ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
>                 source.Execute(scope);
>                 string class_param = rule;
>                 object[] parameters = new object[1];
>                 parameters[0] = class_param;
>                 object klass = scope.GetVariable("model_checker");
>                 object instance = ops.Invoke(klass, parameters);
>                 method = ops.GetMember(instance, "check_model");
>
> 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.
> 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.
>
> Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering with each other?
>
> any ideas greatly appreciated
>
> _______________________________________________
> Users mailing list
> Users@...
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>

 


_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

 


_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: WPF module in IronPython scripting?

Lukáš Duběda
In reply to this post by Dino Viehland
Unfortunately loading the Assembly didn't work, it threw an error:

dotNet runtime exception: Could not add reference to assembly
IronPython.Wpf.dll

Nothing else. :(

Unfortunately we don't have access to the Host app's source at all,
we're only writing a .NET plugin that enables us to run IronPython
inside the host app's native scripting language.

But I'll talk to the programmer who wrote the actual IPy plugin
for me and see what the problem might be.

I just thought it's something related to .NET and IPy only.

Thank you!

Lukáš Duběda
Director
[T] +420 602 444 164

duber studio(tm)
[M] [hidden email]
[W] http://www.duber.cz

[A] R.A.Dvorského 601, Praha 10
[A] 10900, Czech Republic, Europe

On 15.4.2011 18:38, Dino Viehland wrote:

> Lukáš wrote:
>> Hi there everyone,
>>
>> I just bumped into a problem where when I run the IPy.exe console and
>> execute a script that contains:
>>
>> import wpf
>>
>> all works well. However, when I want to import the wpf namespace into the
>> same script, but run outside the IPy.exe (i.e. as an embedded engine) I get
>> an error saying that the module wpf doesn't exist!
>>
>> I even tried to add the IronPython.Wpf.dll into the PATH, I tried referencing
>> it in my script via clr.AddReferenceToFile, nothing works and I don't have
>> access to the wpf methods etc...
>>
>> Is there anything I can do about it?
>
> I would have expected AddReferenceToFile to work but what about doing a
> scriptRuntime.LoadAssembly(typeof(Wpf).Assembly);  where the host app
> has a reference to IronPython.Wpf.dll?
>
> I think the code for loading from the DLLs directory is ipy.exe specific - you could
> also look at replicating that for your host app so there's a general way to add
> additional Python built-in modules.
>
>
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: WPF module in IronPython scripting?

Markus Schaber-6
Hi, Lukáš,

It may be a problem related to the .NET assembly search path, or it may be the host application blocking/filtering the loading of arbitrary assemblies.

Did you try clr.AddReference() with the Assemblies being in the GAC?

Did you try clr.AddReferencetoFileAndPath()?

Could you try to catch the exception, and explore it for more details (e. G. an inner exception)?

Regards,
Markus

> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:users-
> [hidden email]] Im Auftrag von Lukáš Dubeda
> Gesendet: Freitag, 15. April 2011 19:41
> An: Discussion of IronPython
> Betreff: Re: [IronPython] WPF module in IronPython scripting?
>
> Unfortunately loading the Assembly didn't work, it threw an error:
>
> dotNet runtime exception: Could not add reference to assembly
> IronPython.Wpf.dll
>
> Nothing else. :(
>
> Unfortunately we don't have access to the Host app's source at all, we're
> only writing a .NET plugin that enables us to run IronPython inside the
> host app's native scripting language.
>
> But I'll talk to the programmer who wrote the actual IPy plugin for me and
> see what the problem might be.
>
> I just thought it's something related to .NET and IPy only.
>
> Thank you!
>
> Lukáš Duběda
> Director
> [T] +420 602 444 164
>
> duber studio(tm)
> [M] [hidden email]
> [W] http://www.duber.cz
>
> [A] R.A.Dvorského 601, Praha 10
> [A] 10900, Czech Republic, Europe
>
> On 15.4.2011 18:38, Dino Viehland wrote:
> > Lukáš wrote:
> >> Hi there everyone,
> >>
> >> I just bumped into a problem where when I run the IPy.exe console and
> >> execute a script that contains:
> >>
> >> import wpf
> >>
> >> all works well. However, when I want to import the wpf namespace into
> >> the same script, but run outside the IPy.exe (i.e. as an embedded
> >> engine) I get an error saying that the module wpf doesn't exist!
> >>
> >> I even tried to add the IronPython.Wpf.dll into the PATH, I tried
> >> referencing it in my script via clr.AddReferenceToFile, nothing works
> >> and I don't have access to the wpf methods etc...
> >>
> >> Is there anything I can do about it?
> >
> > I would have expected AddReferenceToFile to work but what about doing
> > a scriptRuntime.LoadAssembly(typeof(Wpf).Assembly);  where the host
> > app has a reference to IronPython.Wpf.dll?
> >
> > I think the code for loading from the DLLs directory is ipy.exe
> > specific - you could also look at replicating that for your host app
> > so there's a general way to add additional Python built-in modules.
> >
> >
> > _______________________________________________
> > Users mailing list
> > [hidden email]
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: how to generate multiple concurrent scriptign engines?

suralk
In reply to this post by Jeff Hardy-4
Hi,
Sorry I missed the posts on this thread. This is the code that caused me the problem (I posted this in the first post of the thread)
So according to your mails, I take that this is due to a bug in the ironpython code. Is there a way I can have some alternative work-out, something that I can do through my code? (i'm in kind of a hury to finish the project :S )
 
ScriptEngine engine = Python.CreateEngine();
ScriptRuntime runtime = engine.Runtime;
ScriptScope scope = runtime.CreateScope();
ops = engine.Operations;
try
{
ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
source.Execute(scope);
string class_param = rule;
object[] parameters = new object[1];
parameters[0] = class_param;
object klass = scope.GetVariable("model_checker");
object instance = ops.Invoke(klass, parameters);
method = ops.GetMember(instance, "check_model");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
 
 


--- On Thu, 14/4/11, Jeff Hardy <[hidden email]> wrote:

From: Jeff Hardy <[hidden email]>
Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?
To: "Discussion of IronPython" <[hidden email]>
Cc: "surangika ranathunga" <[hidden email]>
Received: Thursday, 14 April, 2011, 7:35 AM

As long as you have a ScriptScope per thread, you should be able to
share the ScriptEngine & Runtime between threads.

What is the exception that you are getting? If it's a GUI program,
remember that UI elements can only be manipulated from the main
thread.

- Jeff

On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga
<lady_radsu@...> wrote:

>
> Hi,
> I am using Ironpython to connect to a legacy python code from C#.
> I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.
> This is how I implemented this:
>
>                 ScriptEngine engine = Python.CreateEngine();
>                 ScriptRuntime runtime = engine.Runtime;
>                 ScriptScope scope = runtime.CreateScope();
>                 ops = engine.Operations;
>                 ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
>                 source.Execute(scope);
>                 string class_param = rule;
>                 object[] parameters = new object[1];
>                 parameters[0] = class_param;
>                 object klass = scope.GetVariable("model_checker");
>                 object instance = ops.Invoke(klass, parameters);
>                 method = ops.GetMember(instance, "check_model");
>
> 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.
> 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.
>
> Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering with each other?
>
> any ideas greatly appreciated
>
> _______________________________________________
> Users mailing list
> Users@...
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>

_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: how to generate multiple concurrent scriptignengines?

Markus Schaber-6

Hi,

 

You can re-read the thread at http://lists.ironpython.com/pipermail/users-ironpython.com/.

 

The fastest possibility is:

- Fetch the IronPython source.

- Patch PythonContext.GetEqualSite yourself according to the description in the thread.

- Use your own compiled version.

 

Grüße,

Markus

 

Von: [hidden email] [mailto:[hidden email]] Im Auftrag von surangika ranathunga
Gesendet: Dienstag, 19. April 2011 04:28
An: Discussion of IronPython; Jeff Hardy
Betreff: Re: [IronPython] how to generate multiple concurrent scriptignengines?

 

Hi,

Sorry I missed the posts on this thread. This is the code that caused me the problem (I posted this in the first post of the thread)

So according to your mails, I take that this is due to a bug in the ironpython code. Is there a way I can have some alternative work-out, something that I can do through my code? (i'm in kind of a hury to finish the project :S )

 

ScriptEngine engine = Python.CreateEngine();

ScriptRuntime runtime = engine.Runtime;

ScriptScope scope = runtime.CreateScope();

ops = engine.Operations;

try

{

ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");

source.Execute(scope);

string class_param = rule;

object[] parameters = new object[1];

parameters[0] = class_param;

object klass = scope.GetVariable("model_checker");

object instance = ops.Invoke(klass, parameters);

method = ops.GetMember(instance, "check_model");

}

catch (Exception e)

{

Console.WriteLine(e.ToString());

}

 

 



--- On Thu, 14/4/11, Jeff Hardy <[hidden email]> wrote:


From: Jeff Hardy <
[hidden email]>
Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?
To: "Discussion of IronPython" <
[hidden email]>
Cc: "surangika ranathunga" <
[hidden email]>
Received: Thursday, 14 April, 2011, 7:35 AM

As long as you have a ScriptScope per thread, you should be able to
share the ScriptEngine & Runtime between threads.

What is the exception that you are getting? If it's a GUI program,
remember that UI elements can only be manipulated from the main
thread.

- Jeff

On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga
<lady_radsu@...> wrote:


>
> Hi,
> I am using Ironpython to connect to a legacy python code from C#.
> I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.
> This is how I implemented this:
>
>                 ScriptEngine engine = Python.CreateEngine();
>                 ScriptRuntime runtime = engine.Runtime;
>                 ScriptScope scope = runtime.CreateScope();
>                 ops = engine.Operations;
>                 ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
>                 source.Execute(scope);
>                 string class_param = rule;
>                 object[] parameters = new object[1];
>                 parameters[0] = class_param;
>                 object klass = scope.GetVariable("model_checker");
>                 object instance = ops.Invoke(klass, parameters);
>                 method = ops.GetMember(instance, "check_model");
>
> 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.
> 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.
>
> Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering with each other?
>
> any ideas greatly appreciated
>
> _______________________________________________
> Users mailing list
> Users@...
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>

 

_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: how to generate multiple concurrent scriptignengines?

suralk
I applied the suggested patch and have been testing it for quite a few days. The exception did not occur ever since. So I think I can assume that the problem is no longer there. Thanks a lot for all your timely help

--- On Tue, 19/4/11, Markus Schaber <[hidden email]> wrote:

From: Markus Schaber <[hidden email]>
Subject: Re: [IronPython] how to generate multiple concurrent scriptignengines?
To: "Discussion of IronPython" <[hidden email]>
Received: Tuesday, 19 April, 2011, 11:23 PM

Hi,

 

You can re-read the thread at http://lists.ironpython.com/pipermail/users-ironpython.com/.

 

The fastest possibility is:

- Fetch the IronPython source.

- Patch PythonContext.GetEqualSite yourself according to the description in the thread.

- Use your own compiled version.

 

Grüße,

Markus

 

Von: [hidden email] [mailto:[hidden email]] Im Auftrag von surangika ranathunga
Gesendet: Dienstag, 19. April 2011 04:28
An: Discussion of IronPython; Jeff Hardy
Betreff: Re: [IronPython] how to generate multiple concurrent scriptignengines?

 

Hi,

Sorry I missed the posts on this thread. This is the code that caused me the problem (I posted this in the first post of the thread)

So according to your mails, I take that this is due to a bug in the ironpython code. Is there a way I can have some alternative work-out, something that I can do through my code? (i'm in kind of a hury to finish the project :S )

 

ScriptEngine engine = Python.CreateEngine();

ScriptRuntime runtime = engine.Runtime;

ScriptScope scope = runtime.CreateScope();

ops = engine.Operations;

try

{

ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");

source.Execute(scope);

string class_param = rule;

object[] parameters = new object[1];

parameters[0] = class_param;

object klass = scope.GetVariable("model_checker");

object instance = ops.Invoke(klass, parameters);

method = ops.GetMember(instance, "check_model");

}

catch (Exception e)

{

Console.WriteLine(e.ToString());

}

 

 



--- On Thu, 14/4/11, Jeff Hardy <jdhardy@...> wrote:


From: Jeff Hardy <
jdhardy@...>
Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?
To: "Discussion of IronPython" <
users@...>
Cc: "surangika ranathunga" <
lady_radsu@...>
Received: Thursday, 14 April, 2011, 7:35 AM

As long as you have a ScriptScope per thread, you should be able to
share the ScriptEngine & Runtime between threads.

What is the exception that you are getting? If it's a GUI program,
remember that UI elements can only be manipulated from the main
thread.

- Jeff

On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga
<lady_radsu@...> wrote:


>
> Hi,
> I am using Ironpython to connect to a legacy python code from C#.
> I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.
> This is how I implemented this:
>
>                 ScriptEngine engine = Python.CreateEngine();
>                 ScriptRuntime runtime = engine.Runtime;
>                 ScriptScope scope = runtime.CreateScope();
>                 ops = engine.Operations;
>                 ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
>                 source.Execute(scope);
>                 string class_param = rule;
>                 object[] parameters = new object[1];
>                 parameters[0] = class_param;
>                 object klass = scope.GetVariable("model_checker");
>                 object instance = ops.Invoke(klass, parameters);
>                 method = ops.GetMember(instance, "check_model");
>
> 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.
> 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.
>
> Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering with each other?
>
> any ideas greatly appreciated
>
> _______________________________________________
> Users mailing list
> Users@...
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>

 

-----Inline Attachment Follows-----

_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com