[ZODB-Dev] Fixing Broken Objects?
Tim Peters
tim.one at comcast.net
Fri Oct 14 15:50:59 EDT 2005
[Tino Wildenhain]
> ...
> Btw, (hijacking the thread because a bit related) how can I serialize the
> state of a generator object? (e.g. for caching it between requests)
> Pickle does not work for it (whyever)
You cannot. A generator-iterator contains (among other things) a Python
stack frame, and you can't even serialize one of those by itself (let alone
a generator containing one). For that matter, a Python stack frame contains
a Python code object and a Python thread state, which latter includes
addresses of C functions and a Python interpreter state, which in turn
contains a linked list of Python thread states ... there's nothing on Earth
_less_ serializable than a generator ;-). That goes beyond "serializing
code" to "serializing code and its current execution state in midstream"
too.
It's possible that PyPy will (or already has) a kind of object space in
which this is possible, but I don't except it will ever be possible in
CPython.
More information about the ZODB-Dev
mailing list