Lukas, this is the bug in Microsoft.Scripting.Silverlight. Because you do "<tt>setup.HostType =
typeof(Microsoft.Scripting.Silverlight.BrowserScriptHost)</tt>", all file-system lookups (like looking for a module) go through that type.<br><br clear="all">~Jimmy<br>
<br><br><div class="gmail_quote">On Wed, Aug 18, 2010 at 3:23 AM, Lukas Cenovsky <span dir="ltr"><<a href="mailto:cenovsky@bakalari.cz">cenovsky@bakalari.cz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
Looks like there is a bug in DynamicEngine. When I tried the old
way, it works:<br>
<br>
<tt><div class="im">private void UserControl_Loaded(object sender, RoutedEventArgs
ev)<br>
{<br>
IPloader = new BackgroundWorker();<br>
IPloader.DoWork += new DoWorkEventHandler((s, e) =><br>
{<br></div>
ScriptRuntimeSetup setup = new ScriptRuntimeSetup();<br>
setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));<br>
setup.HostType =
typeof(Microsoft.Scripting.Silverlight.BrowserScriptHost);<br>
setup.DebugMode = true;<br>
runtime = new ScriptRuntime(setup);<br>
engine = Python.GetEngine(runtime);<br>
foreach (string str in new string[] { "mscorlib",
"System", "System.Windows", "System.Windows.Browser", "System.Net"
})<br>
{<br>
runtime.LoadAssembly(runtime.Host.PlatformAdaptationLayer.LoadAssembly(str));<br>
}<br>
// engine.Execute("import imptest"); --this does not
work<div class="im"><br>
}<br>
);<br>
IPloader.RunWorkerCompleted += new
RunWorkerCompletedEventHandler((s, e) =><br>
{<br>
this.textBlock1.Text = "IronPython loaded";<br>
}<br>
);<br>
IPloader.RunWorkerAsync();<br>
}<br>
</div></tt><br>
What does not work is importing modules in the background thread
(commented line). It throws the following exception:<br>
<br>
<tt>System.InvalidOperationException was unhandled by user code<br>
Message=This operation can only occur on the UI Thread.<br>
StackTrace:<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.Run1[T0,TRet](T0 arg0)<br>
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope
scope)<br>
at IronPython.Compiler.RuntimeScriptCode.Run()<br>
at Microsoft.Scripting.SourceUnit.Execute()<br>
at Microsoft.Scripting.Hosting.ScriptSource.Execute()<br>
at Microsoft.Scripting.Hosting.ScriptEngine.Execute(String
expression)<div class="im"><br>
at SLHosting.MainPage.<UserControl_Loaded>b__0(Object
s, DoWorkEventArgs e)<br>
at
System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)<br>
at System.ComponentModel.BackgroundWorker.OnRun(Object
argument)<br>
InnerException: </div></tt><br>
<br>
<tt>runtime.ImportModule("imptest");</tt> is similar story so I
guess it cannot be done, right?<br><font color="#888888">
<br>
--<br>
-- Lukáš</font><div><div></div><div class="h5"><br>
<br>
<br>
On 18.8.2010 5:05, Jimmy Schementi wrote:
<blockquote type="cite">True, but according to his exception stack it never
gets there ... it throws on the "runtime =
DynamicEngine.CreateRuntime(true);" line. It throws because
somewhere in that method it doesn't dispatch to the UI thread as
you described. Those are the fixes I need to do.<br clear="all">
<br>
~Jimmy<br>
<br>
<br>
<div class="gmail_quote">2010/8/17 Dave Curylo <span dir="ltr"><<a href="mailto:curylod@asme.org" target="_blank">curylod@asme.org</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Lukas,
<div><br>
</div>
<div>I think the problem is the RunWorkerCompleted handler
trying to update the UI. Wrap calls from a background thread
to update UI controls in something like this so the
Dispatcher updates any controls on the UI thread:</div>
<div><br>
</div>
<div>
<div>this.Dispatcher.BeginInvoke(() =></div>
<div>
<div> {</div>
<div> this.textBlock1.Text = "IronPython loaded";</div>
<div> });</div>
<div><br>
</div>
</div>
<div>Hope that helps.</div>
<div>
<br>
</div>
<div>-Dave</div>
<br>
<div class="gmail_quote">2010/8/17 Lukas Cenovsky <span dir="ltr"><<a href="mailto:cenovsky@bakalari.cz" target="_blank">cenovsky@bakalari.cz</a>></span>
<div>
<div><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi all,<br>
is it possible to load IronPython engine in the
background thread in Silverlight?<br>
<br>
I tried to load it via BackgroundWorker:<br>
<br>
private void UserControl_Loaded(object sender,
RoutedEventArgs ev)<br>
{<br>
IPloader = new BackgroundWorker();<br>
IPloader.DoWork += new DoWorkEventHandler((s, e)
=><br>
{<br>
runtime =
DynamicEngine.CreateRuntime(true); // debug mode
true<br>
engine = runtime.GetEngine("python");<br>
}<br>
);<br>
IPloader.RunWorkerCompleted += new
RunWorkerCompletedEventHandler((s, e) =><br>
{<br>
this.textBlock1.Text = "IronPython loaded";<br>
}<br>
);<br>
IPloader.RunWorkerAsync();<br>
}<br>
<br>
It fails with the following exception:<br>
<br>
System.UnauthorizedAccessException was unhandled by
user code<br>
Message=Invalid cross-thread access.<br>
StackTrace:<br>
at MS.Internal.XcpImports.CheckThread()<br>
at
System.Windows.DependencyObject.GetValueInternal(DependencyProperty
dp)<br>
at System.Windows.Deployment.get_Parts()<br>
at
Microsoft.Scripting.Silverlight.DynamicAppManifest.AssemblyParts()<br>
at
Microsoft.Scripting.Silverlight.DynamicAppManifest..ctor()<br>
at
Microsoft.Scripting.Silverlight.DynamicEngine.CreateLangConfig()<br>
at
Microsoft.Scripting.Silverlight.DynamicEngine.CreateRuntimeSetup(Boolean
debugMode)<br>
at
Microsoft.Scripting.Silverlight.DynamicEngine.CreateRuntime(Boolean
debugMode)<br>
at
SLHosting.MainPage.<UserControl_Loaded>b__0(Object
s, DoWorkEventArgs e)<br>
at
System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs
e)<br>
at
System.ComponentModel.BackgroundWorker.OnRun(Object
argument)<br>
InnerException:<br>
<br>
Thanks for any advice.<br>
<font color="#888888">
<br>
--<br>
-- Lukáš<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto: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>
</font></blockquote>
</div>
</div>
</div>
<br>
</div>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto: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>
</blockquote>
</div>
<br>
<pre><fieldset></fieldset>
_______________________________________________
Users mailing list
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a>
</pre>
</blockquote>
<br>
</div></div></div>
<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">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></blockquote></div><br>