Message54348
Logged In: YES
user_id=341410
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
else:
#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
state
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:14 | admin | link | issue1092962 messages |
2007-08-23 16:10:14 | admin | create | |
|