cloudpickle-generators
cloudpickle <https://github.com/cloudpipe/cloudpickle>
_ support for
generators, including partially consumed generators.
To use cloudpickle-generators
, you must simply call register
. After
calling register, you may use cloudpickle
like normal.
.. code-block:: python
import cloudpickle import cloudpickle_generators
cloudpickle_generators.register()
def f(a, b): ... for n in range(a): ... yield b + b[-1] * n
gen = f(4, 'ay')
next(gen) ay next(gen) ayy
new_gen = cloudpickle.loads(cloudpickle.dumps(gen)) new_gen is gen False
next(new_gen) ayyy next(new_gen) ayyyy next(new_gen) Traceback (most recent call last): ... StopIteration
next(gen) ayyy next(gen) ayyyy next(gen) Traceback (most recent call last): ... StopIteration