[IronPython] import thread-safety

Dino Viehland dinov at microsoft.com
Tue Mar 10 11:21:37 PDT 2009


This is fixed in 2.6 and we can backport the fix to 2.0.  Could you open a bug on CodePlex?  If you want to add the fix locally you just need to add the lock statement below to NewTypeMaker.StoreOverriddenMethods:

	lock(PythonTypeOps._functions) {
            foreach (BuiltinFunction bf in PythonTypeOps._functions.Values) {
                if (bf.Name == pythonName && bf.DeclaringType == declType) {
                    bf.AddMethod(mi);
                    break;
                }
            }
	}

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Kamil Dworakowski
> Sent: Tuesday, March 10, 2009 11:08 AM
> To: users at lists.ironpython.com
> Subject: [IronPython] import thread-safety
> 
> Hello,
> 
> I tried reactivate parallel importing in Resolver One. More info in
> this thread from October:
> http://groups.google.com/group/ironpy/browse_thread/thread/11c5c917d716
> b7cc/58ce4e4260c2773a?lnk=gst&q=parallel+import#58ce4e4260c2773a
> 
> I hit a problem. Sometimes during importing I get the following
> exception. It is a bit of a haisenbug because whenever I try to add
> some diagnostics Resolver One starts fine.
> 
> CLS Exception: System.InvalidOperationException: Collection was
> modified; enumeration operation may not execute.
>    at System.ThrowHelper.ThrowInvalidOperationException
> (ExceptionResource resource)
>    at
> System.Collections.Generic.Dictionary`2.ValueCollection.Enumerator.Move
> Next
> ()
>    at IronPython.Runtime.Types.NewTypeMaker.StoreOverriddenMethod
> (MethodInfo mi, String newName)
>    at IronPython.Runtime.Types.NewTypeMaker.AddBaseMethods(Type
> finishedType, Dictionary`2 specialNames)
>    at IronPython.Runtime.Types.NewTypeMaker.CreateNewType()
>    at
> IronPython.Runtime.Types.NewTypeMaker.<>c__DisplayClass1.<GetNewType>b_
> _0
> ()
>    at Microsoft.Scripting.Utils.Publisher`2.GetOrCreateValue(TKey key,
> Func`1 create)
>    at IronPython.Runtime.Types.NewTypeMaker.GetNewType(String
> typeName, PythonTuple bases, IAttributesCollection dict)
>    at IronPython.Runtime.Types.PythonType..ctor(CodeContext context,
> String name, PythonTuple bases, IAttributesCollection dict)
>    at IronPython.Runtime.Types.PythonType.__new__(CodeContext context,
> PythonType cls, String name, PythonTuple bases, IAttributesCollection
> dict)
>    at _stub_$270##128(Closure , CallSite , CodeContext , Object ,
> String , PythonTuple , IAttributesCollection )
>    at IronPython.Runtime.Operations.PythonOps.MakeClass(CodeContext
> context, String name, Object[] bases, String selfNames,
> IAttributesCollection vars)
>    at IronPython.Runtime.Operations.PythonOps.MakeClass(CodeContext
> context, String name, Object[] bases, String selfNames, CallTarget0
> body)
>    at DLRCachedCode.Main\RenameWorksheetTextBoxAdaptor(Scope $scope,
> LanguageContext $language)
>    at Microsoft.Scripting.ScriptCode.InvokeTarget(LambdaExpression
> code, Scope scope)
>    at Microsoft.Scripting.ScriptCode.Run(Scope scope)
>    at IronPython.Runtime.PythonContext.CreateModule(String fileName,
> Scope scope, ScriptCode scriptCode, ModuleOptions options)
>    at IronPython.Runtime.ModuleLoader.load_module(CodeContext context,
> String fullName)
>    at _stub_$367##225(Closure , CallSite , CodeContext , Object ,
> Object[] )
>    at IronPython.Runtime.PythonContext.Call(Object func, Object[]
> args)
>    at IronPython.Runtime.Importer.FindAndLoadModuleFromImporter
> (CodeContext context, Object importer, String fullName, List path,
> Object& ret)
>    at IronPython.Runtime.Importer.TryLoadMetaPathModule(CodeContext
> context, String fullName, List path, Object& ret)
>    at IronPython.Runtime.Importer.TryGetExistingOrMetaPathModule
> (CodeContext context, String fullName, List path, Object& ret)
>    at IronPython.Runtime.Importer.ImportNestedModule(CodeContext
> context, Scope scope, String name, List path)
>    at IronPython.Runtime.Importer.ImportModuleFrom(CodeContext
> context, Object from, String name)
>    at IronPython.Runtime.Importer.ImportModule(CodeContext context,
> Object globals, String modName, Boolean bottom, Int32 level)
>    at IronPython.Runtime.Builtin.__import__(CodeContext context,
> String name, Object globals, Object locals, Object fromlist, Int32
> level)
>    at IronPython.Runtime.Builtin.__import__(CodeContext context,
> String name)
>    at _stub_$548##406(Closure , CallSite , CodeContext , Object ,
> Object )
>    at DLRCachedCode.worker$736(Closure )
> CLS Stack trace:
> 
>    at System.ThrowHelper.ThrowInvalidOperationException
> (ExceptionResource resource)
>    at
> System.Collections.Generic.Dictionary`2.ValueCollection.Enumerator.Move
> Next
> ()
>    at IronPython.Runtime.Types.NewTypeMaker.StoreOverriddenMethod
> (MethodInfo mi, String newName)
>    at IronPython.Runtime.Types.NewTypeMaker.AddBaseMethods(Type
> finishedType, Dictionary`2 specialNames)
>    at IronPython.Runtime.Types.NewTypeMaker.CreateNewType()
>    at
> IronPython.Runtime.Types.NewTypeMaker.<>c__DisplayClass1.<GetNewType>b_
> _0
> ()
>    at Microsoft.Scripting.Utils.Publisher`2.GetOrCreateValue(TKey key,
> Func`1 create)
>    at IronPython.Runtime.Types.NewTypeMaker.GetNewType(String
> typeName, PythonTuple bases, IAttributesCollection dict)
>    at IronPython.Runtime.Types.PythonType..ctor(CodeContext context,
> String name, PythonTuple bases, IAttributesCollection dict)
>    at IronPython.Runtime.Types.PythonType.__new__(CodeContext context,
> PythonType cls, String name, PythonTuple bases, IAttributesCollection
> dict)
>    at _stub_$270##128(Closure , CallSite , CodeContext , Object ,
> String , PythonTuple , IAttributesCollection )
>    at IronPython.Runtime.Operations.PythonOps.MakeClass(CodeContext
> context, String name, Object[] bases, String selfNames,
> IAttributesCollection vars)
>    at IronPython.Runtime.Operations.PythonOps.MakeClass(CodeContext
> context, String name, Object[] bases, String selfNames, CallTarget0
> body)
>    at DLRCachedCode.Main\RenameWorksheetTextBoxAdaptor(Scope $scope,
> LanguageContext $language)
>    at Microsoft.Scripting.ScriptCode.InvokeTarget(LambdaExpression
> code, Scope scope)
>    at Microsoft.Scripting.ScriptCode.Run(Scope scope)
>    at IronPython.Runtime.PythonContext.CreateModule(String fileName,
> Scope scope, ScriptCode scriptCode, ModuleOptions options)
>    at IronPython.Runtime.ModuleLoader.load_module(CodeContext context,
> String fullName)
>    at _stub_$367##225(Closure , CallSite , CodeContext , Object ,
> Object[] )
>    at IronPython.Runtime.PythonContext.Call(Object func, Object[]
> args)
>    at IronPython.Runtime.Importer.FindAndLoadModuleFromImporter
> (CodeContext context, Object importer, String fullName, List path,
> Object& ret)
>    at IronPython.Runtime.Importer.TryLoadMetaPathModule(CodeContext
> context, String fullName, List path, Object& ret)
>    at IronPython.Runtime.Importer.TryGetExistingOrMetaPathModule
> (CodeContext context, String fullName, List path, Object& ret)
>    at IronPython.Runtime.Importer.ImportNestedModule(CodeContext
> context, Scope scope, String name, List path)
>    at IronPython.Runtime.Importer.ImportModuleFrom(CodeContext
> context, Object from, String name)
>    at IronPython.Runtime.Importer.ImportModule(CodeContext context,
> Object globals, String modName, Boolean bottom, Int32 level)
>    at IronPython.Runtime.Builtin.__import__(CodeContext context,
> String name, Object globals, Object locals, Object fromlist, Int32
> level)
>    at IronPython.Runtime.Builtin.__import__(CodeContext context,
> String name)
>    at _stub_$548##406(Closure , CallSite , CodeContext , Object ,
> Object )
>    at DLRCachedCode.worker$736(Closure )
> 
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Users mailing list