[pypy-dev] Pickling generators

Steven D'Aprano steve at pearwood.info
Fri Dec 11 15:49:48 EST 2020


On Fri, Dec 11, 2020 at 03:21:18PM +0200, Matti Picus wrote:
> According to issue 3150 
> https://foss.heptapod.net/pypy/pypy/-/issues/3150, this is on purpose, 
> and brings us into feature compatibility with CPython:

The inability to pickle an object is not a feature, it is the lack of a 
feature. I think this is a case where PyPy initially did the right thing 
and then threw it away.

I'm not satisfied by the arguments given here:

http://peadrop.com/blog/2009/12/29/why-you-cannot-pickle-generators/

https://bugs.python.org/issue1092962

for CPython to not pickle generators, but pickling generators is not 
forbidden by the language, it is a quality of implementation issue. In 
this instance, both Stackless and PyPy 2 had better implementations than 
CPython.


> I guess we could improve the error message to be more helpful. Do you 
> have a concrete use case for this?

You have a generator which you are iterating through, and you want to 
stop your program and resume later. Or resume immediately but from 
another process.


-- 
Steve


More information about the pypy-dev mailing list