[Stackless] killing tasklets

Kristján Valur Jónsson kristjan at ccpgames.com
Fri Nov 23 17:41:19 CET 2007


One additional thing:
tasklet.kill() only causes an exception for a tasklet if it is blocked on a channel, apparently.
A tasklet that has done stackless.schedule(), and receives a kill(), just silently goes away, that is, its frames are just released and nothing runs more.

I think that we should always get a TaskletExit exception, so that proper cleanup can be performed.  At least if there is a frame.  For tasklets that haven't run yet of course this isn't required.

Kristján

> -----Original Message-----
> From: stackless-bounces at stackless.com [mailto:stackless-
> bounces at stackless.com] On Behalf Of Kristján Valur Jónsson
> Sent: Friday, November 23, 2007 11:34
> To: Christian Tismer
> Cc: Stackless mailing list
> Subject: Re: [Stackless] killing tasklets
>
>
>
> > -----Original Message-----
> > We can have another flag, probably a computed one,
> > if it is useful.
> >
> > But simply ignoring this and killing right away should
> > be fine in this case.
>
> Well, the thing is, we expect all tasklets to run to their end, with
> something like:
>
> def Wrap():
>         try:
>                 tasklet_func()
>         finally:
>                 signal_that_tasklet_is_done(self)
>
> And then let the tasklet run the Wrap() function.
> All tasklets are guaranteed to reach the finally clause, except
> tasklets that are killed before they get the chance to be run in the
> first place.  So, we need to have a special case to handle them.  Here
> is how one could do this:
>
> def Kill(tasklet):
>         try:
>                 tasklet.run()  #make sure it runs
>         except:
>                 pass
>         tasklet.kill()
>
> def Kill(t):
>         if tasklet_hasnt_run(t):
>                 t.remove()
>                 signal_that_tasklet_is_done(t)
>         else:
>                 t.kill()
>
> All are a bit nasty because they mean that we can't just t.kill(),  we
> suddenly have coupling to the tasklet bookkeeping at the site where we
> do the killing.
>
> We could also make sure that a fresh tasklet is always t.run() thus
> avoiding the issue, but that would constrain us too much.  Sometimes we
> want to construct a tasklet for running later.
>
> Ok, My final idea is to add a "started" attribute to the tasklet
> subclass which is set to True in the Wrapper function.  We can then
> define an overriding kill() method which tests for this...  That is
> perhaps the simples.
>
> K
>
> _______________________________________________
> Stackless mailing list
> Stackless at stackless.com
> http://www.stackless.com/mailman/listinfo/stackless





More information about the Stackless mailing list