[Ironpython-users] IronPython (ScriptEngine) is not thread safe?

Zsidó Zoltán zsidoz at innodev.hu
Mon Mar 2 13:24:51 CET 2015


This is about: https://github.com/IronLanguages/main/issues/1173

I have never analysed IronPython source code, I just try to help you.

I modified:


to this:

        public void ChainCallback(object callback, object weakRef) {

            lock (callbacks)


                callbacks.Add(new CallbackInfo(callback, weakRef));



Now it is better.

Now sometimes I get this exceptions:

'module' object has no attribute '__all__'

   at Microsoft.Scripting.Runtime.LightExceptions.CheckAndThrow(Object 

   at os$10._get_exports_list$98(PythonFunction $function, Object module) 
hely: C:\Program Files (x86)\IronPython 2.7\Lib\os.py, sor: 39

   at IronPython.Runtime.FunctionCaller`1.Call1(CallSite site, CodeContext 
context, Object func, T0 arg0)

site, T0 arg0, T1 arg1, T2 arg2)

   at os$10.os(FunctionCode $functionCode) hely: C:\Program Files 
(x86)\IronPython 2.7\Lib\os.py, sor: 743

   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)

   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)

   at IronPython.Runtime.PythonContext.InitializeModule(String fileName, 
ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options)

   at IronPython.Runtime.PythonContext.CompileModule(String fileName, String 
moduleName, SourceUnit sourceCode, ModuleOptions options, ScriptCode& 

   at IronPython.Runtime.PythonContext.CompileModule(String fileName, String 
moduleName, SourceUnit sourceCode, ModuleOptions options)


I do not know why but I cannot localize the error because

putting breakpoint to LightExceptions.CheckAndThrow(Object value) method was 
not working

and this error  rarely occurs

Best Regards


----- Eredeti üzenet ----- 
From: Jeff Hardy
Sent: Sunday, March 1, 2015 4:42 PM
To: Jeffrey Zhao
Cc: ironpython-users at python.org
Subject: Re: [Ironpython-users] IronPython (ScriptEngine) is not thread 

On Thu, Feb 26, 2015 at 9:39 AM, Jeffrey Zhao <jeffz at live.com> wrote:
>  Hi guys,
> I've met an issue when trying to use multiple ScriptEngine instances in
> parallel, since there's no information saying that a single ScriptEngine
> instance could be used concurrently. Please note "thread-safe" is not 
> enough
> for me. What I need is the real parallelized execution in multiple 
> threads,
> so I'm trying to use separated ScriptEngine instances in different 
> threads.

In theory ScriptEngines should be independent and able to run in
parallel without issues. However, there might be interactions with
other parts that still have threading issues (this, BTW, is why
CPython uses a GIL - writing a free-threaded runtime correctly is
*hard*, and it's far to easy to bugs to slip in inadvertantly.)

It looks like this is that same as
https://github.com/IronLanguages/main/issues/1173 that was opened
recently with basically the same problem - there might be a race
condition in the weakref module. I'll try and track it down since
there's a couple of good small test cases to work from.

- Jeff
Ironpython-users mailing list
Ironpython-users at python.org

More information about the Ironpython-users mailing list