[IronPython] Importing in a background thread

Jimmy Schementi Jimmy.Schementi at microsoft.com
Sun Nov 23 00:40:54 CET 2008


Is it a PAL issue? Are you using the BrowserPAL: http://github.com/jschementi/agdlr/tree/master/src/Microsoft.Scripting.Silverlight/BrowserPAL.cs:

public override bool FileExists(string path) {
    if (!DynamicApplication.InUIThread) {
        return false; // Application.GetResourceStream will throw if called from a non-UI thread
    }
    return Package.GetFile(path) != null;
}

When Microsoft.Scripting.Silverlight was written, accessing the XAP from a non-UI thread threw. I don't believe that limitation is there anymore. If this is what's blocking you, feel free to try getting it to work, and send me a pull request when you've got it working.

~js

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Dan Eloff
> Sent: Saturday, November 22, 2008 8:01 AM
> To: Discussion of IronPython
> Subject: Re: [IronPython] Importing in a background thread
>
> On Fri, Nov 21, 2008 at 10:09 PM, Dino Viehland <dinov at microsoft.com>
> wrote:
> > If you're getting crazy and are willing to experiment you could also
> look at IL rewriting compiled modules so they target Silverlight.  In
> theory it's just updating what assembly name we're targeting.
>
> I've been seriously considering that. Better still is if I can do the
> parallel import optimization on top of compiled modules.
>
> > Maybe I've just not been following the Silverlight threads close
> enough but what do you mean by "if __import__ works"?  And how does
> importing in a background thread fail?
>
> Here's a look at the problem in the soon to be released 0.6 version of
> SilverShell:
>
> IronPython 2.0 (2.0.5.0) on SILVERLIGHT (.NET 2.0.31005.0)
> Switching execution to background thread.
> >>> import datetime # builtins work
> >>> import a
> ImportError: No module named a
> >>> __import__('a')
> ImportError: No module named a
> Switching execution to main user-interface thread.
> >>> import a # works
> Switching execution to background thread.
> >>> import a # works now
>
> There is no problem when running this on the desktop version of
> SilverShell.
>
> IronPython 2.0 (2.0.0.0) on CLI (.NET 2.0.50727.3053)
> Switching execution to background thread.
> >>> import datetime
> >>> import a
>
> This does go through exec or eval, but the problem exists when run
> without that as well. This is in RC1, I haven't tested anything newer
> against this problem.
>
> -Dan
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com




More information about the Ironpython-users mailing list