Can a Python generator be easily saved and rebooted from disk?

Is there a way to serialize the generator, the current state and all (local variables, etc.), so that you can later load the line containing the serialized generator and be able to pick it up from the place where the last output instruction went out of function? If so, and you know the sample code web page, please share the link with it.

+6
source share
2 answers

Stackless Python is able to breed generators. Or you can try PyPy 1.7, which also implements many functions without a stack, including etching generators and functions.

Code snippet: http://pastebin.com/p4RkVQkJ

Stackless Python 3.2 and 2.7.2 can be downloaded here: http://zope.stackless.com/download/sdocument_view

PyPy 1.7 can be downloaded here: http://pypy.org/download.html

+5
source

Source: https://habr.com/ru/post/905451/


All Articles