This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josiahcarlson
Date 2005-01-02.18:34:18
SpamBayes Score
Marked as misclassified
Logged In: YES 

In a practical sense I believe this kind of thing is
possible (doing a little spelunking in some generators
reveals gen.gi_frame, which looks to be the stackframe for
the generator).  Why it isn't done could have something to
do with executing on arbitrary stack frames.

In your random-number-generator case, using old-style
iterators via classes can do what you want them to do now
(that is, won't have to wait until Python 2.5 to make it in,
which is at least 1.5 years away).

class g:
    def __init__(self, state=None):
        if state is None:
            #generate some default state
            #process the state to validate and internalize it.
    def __iter__(self):
        return self
    def next(self):
        state = self.state
        ret = #some function on the current internal state
        self.state = #some function on the current internal
        return ret

Heck, you don't even need pickle hooks, because pickle will
pickle your iterator's __dict__ attribute.

Alternatively, you can use Christian Tismer's Stackless
Python, which has generator pickling.
Date User Action Args
2007-08-23 16:10:14adminlinkissue1092962 messages
2007-08-23 16:10:14admincreate