[Stackless] Stackless Digest, Vol 29, Issue 6
Jeff Senn
senn at maya.com
Tue Jun 27 00:54:53 CEST 2006
Andrew Francis wrote:
> 1. For the most part, Stackless is a cooperative
> threading system. You need some kind of event loop
> that calls stackless.schedule(), so tasklets get a
> chance to execute.
>
> If stackless could somehow build a clock interrupt
> that can call schedule() say once a second, or a 60th
> of a second, that would be great. Perhaps there is a
> way to get this effect with the watchdog? I don't
> understand the watchdog well enough
Yes, that is exactly what stackless.run(interval) is for.
Try this as a start:
def run_scheduler():
while 1:
t = stackless.run(100)
if t is None:
do_something_when_there_are_no_tasklets()
else:
t.insert()
In fact, for me, this is the most compelling feature of
stackless (since I am interested in simulating assemblies
of asynchronous dataflows). I have not explored
the 2.5 generators in any depth, but on the surface it looks
like they only support matched entry/exits from a generator --
someone correct me if I'm wrong...
Whereas in stackless, tasklets, using channels, can generate many
output messages for each input -- or vice-versa).
[Actually, channels are not the most interesting part - the ability
of a tasklet to give up control, and later resume, without explicitly
yielding a value is the key!].
If you were to try to build a more general purpose scheduler
out of the 2.5 kind of "continuation" you would need to do some
sort of hack of recursive generators (which, if they wound up calling
back into themselves, would cause the program stack to grow quite
large - probably too large in any "interesting" system) - the removal of
the implicit C-stack frames into the tasklet object itself is the reason
stackless is called "stackless".
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list