[IronPython] importing on different threads

Kamil Dworakowski kamil at dworakowski.name
Thu Aug 21 07:20:49 PDT 2008

We want Resolve One to start quicker. We have found large speedups by
delaying importing of some modules.

This is implemented by moving some import statements into bodies of methods
and function, so that the modules are imported lazily when they are actually
needed. Since Resolver One runs many threads clashes happen.


On Thu, Aug 21, 2008 at 1:53 PM, Curt Hagenlocher <curt at hagenlocher.org>wrote:

> What's the scenario under which you want to do this? Is there a fixed set
> of modules being imported by your application or is the list not known until
> runtime?
> The behavior you describe with respect to sys.modules is identical to that
> in CPython.  In fact, it's required in order to resolve circular imports.
> Without it, if module A were to import module B and module B imported module
> A, you'd end up with infinite recursion.
> Where IronPython is "worse" than CPython in this regard is that it takes us
> longer to import a module.  This increases the chance for a collision in an
> application where modules may be imported from multiple threads.
> On Thu, Aug 21, 2008 at 5:11 AM, Kamil Dworakowski <kamil at dworakowski.name
> > wrote:
>> We are trying parallel imports, which somtimes fail with ImportError (ipy
>> 1.1.1). This happens when one thread attempts to import a module which is
>> being imported on a different thread. The number of such risky imports is
>> not high, and we deal with this by catching the exception and retrying.
>> What do you think? Is it a wrong thing to do? I would like to avoid
>> locking.
>> I have just glimpsed over the IronPython source. Does the problem here is
>> that when one thread starts to import a module it inserts an emty entry into
>> sys.modules, thus other threads get None (or ImportError when using "import
>> from" statement) until the module is fully imported?
>> Kamil Dworakowski
>> Resolver Systems Ltd
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ironpython.com/pipermail/users-ironpython.com/attachments/20080821/a89d998a/attachment-0001.htm>

More information about the Users mailing list