[issue14288] Make iterators pickleable
report at bugs.python.org
Wed Mar 14 16:44:39 CET 2012
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
The dict iterators depend on the order of the dict being the same when unpickled on another python (the order will vary depending on dummy entries, insertion order, 32 vs 64 bit builds, salted hashes, etc). Sets have the same issue -- it doesn't seem possible to pickle a set iterator in a "semi-consumed state" without being able to reproduce the underlying unordered collection in *exactly* the same order and being able to point the resumed iterators to the correct part of memory. Any hacks to make this appear to work would like be hard to reproduce across different implementations of Python (i.e. Jython's dicts are based on Java's concurrent mappings).
There isn't a provision for saving and restoring running generators.
There isn't a provision for iterators created using iter(func, sentinel) where successive func calls change state.
I don't see how str iterators remember where they left off.
Note, the prior effort to make iterators copyable was a failure. It was difficult to do in the general case and the cases we did provide had zero uptake (i.e. they were never used). ISTM, that pickling iterators faces the same issues.
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list