Greenlets: where are they now???

Peter Hansen peter at engcorp.com
Tue Sep 14 12:29:02 CEST 2004


David Pokorny wrote:
> "Peter Hansen" <peter at engcorp.com> wrote:
>>Python's regular threads already allow this, so there must be
>>something more to it.
> 
> I haven't the faintest idea how to gain fine control over threads. 

Not sure what you mean by "fine control".  I was reacting to the
"run for 50 bytecodes" part, which is something all threads do,
based on the current value of sys.setcheckinterval() (which defaults
to 100 now, if I recall correctly).

> In
> particular, suppose I have 10 of these "executions" going (lets call them
> "steplets") and I want to run each of them for 50 byte-codes, then switch
> back to the controlling thread and do lots of bookkeeping (I don't control
> the code that the steplets run). 

Not exactly something regular threads let you do under direct control,
though of course the main thread will run in due course anyway.

 > I also have a bunch of other processes that
> I don't want to take part in this "cycle rationing" but rather run as honest
> threads.

It almost sounds like you want to do this to prevent these other
threads from being able to take up too much CPU time.  I don't
believe the greenlets approach would necessarily guarantee that,
either, since there are bytecodes that can consume unbounded
amounts of time.

You've described the characteristics that you think your
solution requires, but still not the actual problem.  I suspect
the application you have is similar to ones where the usual
response in this newsgroup has been to point out that ultimately
only running this stuff in another process will provide the
guarantees you might need.  (Though this "fine-grained control
with bookkeeping" thing is a little different from the usual
requests.)

-Peter



More information about the Python-list mailing list