Is there a way to serialize a generator, current state and all (local variables, etc), so that you can load the string containing the serialized generator later and be able to pick up right from where the last yield statement exited the function? If yes and you know of a web page with a code sample, please share a link to it.
You should check out generator_tools
' picklegenerator
.
You might also find this article useful: http://metaoptimize.com/blog/2009/12/22/why-cant-you-pickle-generators-in-python-workaround-pattern-for-saving-training-state/
Stackless Python is able to pickle generators. Or you could try PyPy 1.7, which also implements many stackless features, including pickling of generators and functions.
Code snippet: http://pastebin.com/p4RkVQkJ
Stackless Python 3.2 and 2.7.2 could be downloaded here: http://zope.stackless.com/download/sdocument_view
PyPy 1.7 could be downloaded here: http://pypy.org/download.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With