[Python-Dev] Simple generators, round 2
Samuele Pedroni
Samuele Pedroni <pedroni@inf.ethz.ch>
Mon, 19 Mar 2001 18:08:41 +0100 (MET)
Hi.
> > 2) Do not expose the resume and suspend methods to the
> > Python user, and recode Generator.py as an extension
> > module in C. This should prevent abuse of frames.
>
> I like the frame methods. However, this may be a good idea since
> Jython may implement things quite differently.
I should repeat this: (if we want to avoid threads for implementing
generators because for them that's really an overkill, especially
if those are used in tight loops): jython codebase have following
limitations:
- suspensions point should be known at compilation time
(we produce jvm bytecode, that should be instrumented
to allow restart at a given point). The only other solution
is to compile a method with a big switch that have a case
for every python line, which is quite expensive.
- a suspension point can at most do a return, it cannot go up
more than a single frame even if it just want to discard them.
Maybe there is a workaroung to this using exceptions, but they
are expensive and again an overkill for a tight loop.
=> we can support something like a supsend keyword. The rest is pain :-( .
regards.