[Ironpython-users] struct.pack(format, *args) not thread safe

Jeff Hardy jdhardy at gmail.com
Fri Feb 1 21:02:12 CET 2013


On Tue, Jan 29, 2013 at 11:49 PM, Michael van der Kolff
<mvanderkolff at gmail.com> wrote:
> When using paramiko with more than one process spawning, I
> occasionally get the following:
>
> System.InvalidOperationException: The LinkedList node already belongs
> to a LinkedList.
>    at System.Collections.Generic.LinkedList`1.ValidateNewNode(LinkedListNode`1
> node)   at System.Collections.Generic.LinkedList`1.AddFirst(LinkedListNode`1
> node)
>    at IronPython.Modules.PythonStruct.pack(CodeContext context, String
> fmt, Object[] values)
>    at CallSite.Target(Closure , CallSite , CodeContext , Object ,
> String , Object )
>    at paramiko.message$37.add_int$491(PythonFunction $function, Object
> self, Object n) in
> C:\repo\trunk\external\python\paramiko\message.py:line 227
>    at paramiko.message$37.add_string$494(PythonFunction $function,
> Object self, Object s) in
> C:\repo\trunk\external\python\paramiko\message.py:line 259
>    at paramiko.transport$13.open_channel$273(PythonFunction $function,
> Object self, Object kind, Object dest_addr, Object src_addr) in
> C:\repo\trunk\external\python\paramiko\transport.py:line 773
>    ... Lots more in the stack trace.
>
> I think that this is due to PythonStruct.pack's usage of CacheDict,
> which is explicitly marked as not thread safe.  A quick and dirty hack
> would be to force all users of _cache to lock it first, though I'm
> sure there's a better answer.

One of the various Dictionary implementations in IronPython should be
thread safe, but just locking the _chache should be a good-enough
first approximation (I would love to be able to use the Concurrent*
structures in 4.0, but they're not supported everywhere I want them to
be just yet).

Care to open a ticket?

- Jeff


More information about the Ironpython-users mailing list