[Stackless] Problems with removing tasklet.

Christian Tismer tismer at tismer.com
Wed Oct 9 20:46:31 CEST 2002

Håvard Engum wrote:
> Hello!
> I have been having problems with removing tasklets that are running.
> I am only calling the remove() method for the tasklet which has
> a reference in a list. Here agenttasklets is the list:
> self.agenttasklets[agentID].remove()
> I am getting this error-message:
> File "controller.py", line 232, in _removeAgent
>     self.agenttasklets[agentID].remove()
> RuntimeError: The current tasklet cannot be removed. Use
> t=tasklet().capture()
> We have tried using:
> temp = stackless.tasklet(self.agenttasklets[agentID]).capture()
> temp.remove()
> But without much luck.

capture() turns "yourself" into a tasklet.
Suppose you have a tasklet, running function f() and
you want to remove it, you can accomplish that with a function g()
which turns itself into a tasklet and captures its caller:

def f():
    ... do stuff
    g()     # this will do the capture()

def g():
    temp = tasklet().capture()
    # note that this one is removed already

BTW., this info is available via the doctrings.
I suggest to look at all of them, it is the only
documentation at the moment.

Another question: Why do you actually *want* to remove the
current tasklet? I consider it suspicious, if not an error,
when people think they want to do this.

cheers - chris

Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/

Stackless mailing list
Stackless at www.tismer.com

More information about the Stackless mailing list