changeset: 92811:d748a3503ad5 parent: 92810:be4debd9a82e parent: 92809:86ba3bdfac15 user: Antoine Pitrou date: Sat Oct 04 22:17:26 2014 +0200 files: Misc/ACKS Misc/NEWS description: Issue #21905: Avoid RuntimeError in pickle.whichmodule() when sys.modules is mutated while iterating. Patch by Olivier Grisel. diff -r be4debd9a82e -r d748a3503ad5 Lib/pickle.py --- a/Lib/pickle.py Sat Oct 04 22:16:14 2014 +0200 +++ b/Lib/pickle.py Sat Oct 04 22:17:26 2014 +0200 @@ -280,7 +280,9 @@ module_name = getattr(obj, '__module__', None) if module_name is not None: return module_name - for module_name, module in sys.modules.items(): + # Protect the iteration by using a list copy of sys.modules against dynamic + # modules that trigger imports of other modules upon calls to getattr. + for module_name, module in list(sys.modules.items()): if module_name == '__main__' or module is None: continue try: diff -r be4debd9a82e -r d748a3503ad5 Misc/ACKS --- a/Misc/ACKS Sat Oct 04 22:16:14 2014 +0200 +++ b/Misc/ACKS Sat Oct 04 22:17:26 2014 +0200 @@ -498,6 +498,7 @@ Grant Griffin Andrea Griffini Duncan Grisby +Olivier Grisel Fabian Groffen Eric Groo Dag Gruneau diff -r be4debd9a82e -r d748a3503ad5 Misc/NEWS --- a/Misc/NEWS Sat Oct 04 22:16:14 2014 +0200 +++ b/Misc/NEWS Sat Oct 04 22:17:26 2014 +0200 @@ -162,6 +162,9 @@ Library ------- +- Issue #21905: Avoid RuntimeError in pickle.whichmodule() when sys.modules + is mutated while iterating. Patch by Olivier Grisel. + - Issue #11271: concurrent.futures.Executor.map() now takes a *chunksize* argument to allow batching of tasks in child processes and improve performance of ProcessPoolExecutor. Patch by Dan O'Reilly.