[IronPython] IPY and multitasking

Dino Viehland dinov at microsoft.com
Wed Dec 16 20:18:23 CET 2009

Sorry for taking so long on getting back to you on this - PDC and 
Thanksgiving caused this to fall off my radar.

I've taken a look at the repro and ultimately the issues come down
to the fact that we don't have any kind of module importing lock
which is causing things to get imported multiple times.  I'm really
inclined not to fix this the way CPython has (a big importing lock) 
for user defined modules as our users want the ability to import these 
in parallel.  But in your case the problem isn't limited to just user 
defined modules, built in modules are also a problem.  Clearly we 
should make sure each built-in module is only getting loaded once.  
I also think we should probably have some sort of per-file lock so 
that each individual .py file will have its own importing be 

But anyway I was able to make your program work by modifying 
IronPythonHelper.CreateScriptEngine so that it will eagerly import
The things that it needs and then everything else works by adding
this code:

            var scope = scriptEngine.CreateScope();
            scriptEngine.Execute("from utils import Struct", scope);
            scriptEngine.Execute("import cPickle", scope);
            scriptEngine.Execute("import copy_reg", scope);

I realize you've opened a DLR bug for this but because this is an
IronPython bug I've gone ahead and opened an issue in our tracker:


The DLR issue will probably get closed soon.

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Pavel Suhotyuk
> Sent: Friday, November 13, 2009 1:01 AM
> To: Discussion of IronPython
> Subject: Re: [IronPython] IPY and multitasking
> I'm prepare simple test for problem demonstration.
> http://files.roinet.net/DLRTest.zip
> Module utils imported 6-7 times on 2x Dual-Core Opteron 2216 machine,
> but method IronPythonHelper.CreateScript() called one time. On Core 2
> Quad this problem has detected 4 times. On Core 2 Duo problem has not
> detected.
> In file out.txt console output with exceptions and logging information.
> Dino Viehland wrote:
> > You're only using 1 ScriptEngine class?  That should be fine based upon
> > the code below but I just want to make sure I understand the scenario.
> >
> > Is citypay.utils being ran multiple times when you run the code in the
> > multi-threaded scenario?  If you have a console app you could put a
> > print statement in utils.py to see if it's getting executed multiple
> > times.  If it's not a console app you could put some other logging
> > into it.  Executing Struct's definition multiple times might cause
> > the exceptions you're seeing but I don't know why it would get executed
> > multiple times.
> >
> > _______________________________________________
> > 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

More information about the Ironpython-users mailing list