Author Olivier.Grisel
Recipients Olivier.Grisel
Date 2014-07-02.13:03:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1404306192.8.0.184744206475.issue21905@psf.upfronthosting.co.za>
In-reply-to
Content
`pickle.whichmodule` performs an iteration over `sys.modules` and tries to perform `getattr` calls on those modules. Unfortunately some modules such as those from the `six.moves` dynamic module can trigger imports when calling `getattr` on them, hence mutating the `sys.modules` dict and causing a `RuntimeError: dictionary changed size during iteration`.

This would also render `pickle.whichmodule` more thread-safe and cause concurrent thread perform new module imports and `whichmodule` calls.

The attach patch protect the iterator by copying the dict items into a fixed list.

I could write a tests involving dynamic module definitions as done in `six.moves` but it sounds very complicated for such a trivial fix.
History
Date User Action Args
2014-07-02 13:03:12Olivier.Griselsetrecipients: + Olivier.Grisel
2014-07-02 13:03:12Olivier.Griselsetmessageid: <1404306192.8.0.184744206475.issue21905@psf.upfronthosting.co.za>
2014-07-02 13:03:12Olivier.Grisellinkissue21905 messages
2014-07-02 13:03:12Olivier.Griselcreate