[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):
     chan.send(1)

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
         try:
             val = chan.receive()
         except:
             print "Got the exception"
             raise AttributeError

if __name__ == "__main__":
     stackless.tasklet(main)()
     stackless.run()
     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
Abort
%



					Andrew
					dalke at dalkescientific.com


_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list