[Stackless] why the TaskletExit?

Andrew Dalke dalke at dalkescientific.com
Thu Jan 25 01:30:12 CET 2007

On Jan 24, 2007, at 9:17 PM, Richard Tew wrote:
> Right.  Keep in mind that the tasklet for 'main' will have a reference
> to 'chan' and 'chan' will have a reference to tasklets blocking on
> it which just happens to be the same one which holds a referene
> to it.  So there is no way where the tasklet for 'main' can get
> garbage collected until the interpreter exits, ...

It has to be a bit more than that as otherwise Python's cycle
detection in the gc might kick the whole bunch out.

There's a master list of all threadlets.  Seems to be handled
as a bidirectional linked list.  That keeps a reference to
all of the threadlets.  No threadlet should be gc'ed until
explicitly removed from the scheduler or during Python shutdown.

> Of course, I might be confused and what is killing the
> tasklet on interpreter exit is not the garbage collection, but the
> call to PyStackless_kill_tasks_with_stacks.  I don't understand
> why that wouldn't happen regardless of the extra global reference
> though.  So it makes me predisposed towards garbage
> collection.

It's gc.  Here's a simplified version of my code.  I replace the
TaskletExit with an AttributError exception and as a result you
see the message
   Fatal Python error: unexpected exception during garbage collection
and the error occurs *after* normal Python code finishes.

import stackless

def counter(chan, start, end):

def main():
     chan = stackless.channel()
     # Start a new tasket and put it on the end of the task queue
     stackless.tasklet(counter)(chan, 0, 4)

     while 1:
         # Read from the channel.  If the channel is empty this
         # yields control to another tasklett
             val = chan.receive()
             print "Got the exception"
             raise AttributeError

if __name__ == "__main__":
     print "This is the end"

% spython counter.py
This is the end
Got the exception
Exception exceptions.AttributeError: AttributeError() in 'garbage 
collection' ignored
Fatal Python error: unexpected exception during garbage collection

					dalke at dalkescientific.com

Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list