New submission from Olivier Grisel:

`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.

----------
components: Library (Lib)
files: pickle_whichmodule.patch
keywords: patch
messages: 222099
nosy: Olivier.Grisel
priority: normal
severity: normal
status: open
title: RuntimeError in pickle.whichmodule  when sys.modules if mutated
type: crash
versions: Python 3.4, Python 3.5
Added file: http://bugs.python.org/file35830/pickle_whichmodule.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21905>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to