Re: Pickling generators

Steven D'Aprano <[email protected]>
Newsgroups gmane.comp.python.pypy
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.