[IronPython] Importing on another Thread

Dan Eloff dan.eloff at gmail.com
Thu Jul 3 08:07:58 CEST 2008


On Wed, Jul 2, 2008 at 3:34 PM, Jimmy Schementi
<Jimmy.Schementi at microsoft.com> wrote:
> Dan Eloff wrote:
>> I started the thread like so:
>>
>> t = Thread(ThreadStart(preload))
>> t.Start()
>>
>> And I used __import__ to load the modules.
>
> Dan, reason this doesn't work is because the XAP API isn't threadsave, so we fail when trying to use it from a background thread. If you take a look at Microsoft.Scripting.Silverlight/BrowserScriptHost.cs, you're hitting the "if (!DynamicApplication.InUIThread) { return null; }" line in TryGetSourceFile. DynamicApplication.DownloadContents eventually calls Application.GetResourceStream, which will throw if on a background thread.

Aha. I was wondering if Application.GetResourceStream might be the problem.

> It'd be interesting to see if that API is threadsave, since it isn't UI-bound. To be honest, it might be now ... I'll double check.
>
> Today, we spend a large time in the JIT, and the JIT runs on the same thread, so JITing on the UI thread will actually hang your browser. This is what you're trying to avoid, right? In that case, just warming up the DLR on a background thread might be good enough, so we should add that to Microsoft.Scripting.Silverlight.DynamicApplication.
>
> Anyway, I'll see if we can make "import" work on a background thread.
>

Thank you, that would be great. It kind of goes against the language
not to be able to import in a background thread.

-Dan



More information about the Ironpython-users mailing list