[Stackless] Tasklet cleanup?

Sylvain Prat sylvain.prat at gmail.com
Sun May 20 22:02:40 CEST 2012


The simple program I'm trying to get working is attached to this
email. As you can see from the program execution :
- the destructor is not called
- the cleanup is not performed
- the __del__ method make the wrapper, the tasklet and its frame
uncollectable. If I remove the destructor, everything is collectable,
but I still don't get the cleanup performed.

I expected a TaskletExit to be raised but I thought something was bad
in my code. But seeing your examples, it's not just my code ;)

Also, I got no success with tasklet.kill: as I suspected, this method
is used to kill an existing tasklet in user code, and is not called
"automatically" by stackless when a tasklet is garbage collected.

Even if we miss a TaskletExit in stackless, are there workarounds to
make my small program work?


> From: Richard Tew <richard.m.tew at gmail.com>
> To: The Stackless Python Mailing List <stackless at stackless.com>
> Cc: "Kristján Valur Jónsson" <kristjan at ccpgames.com>
> Date: Sun, 20 May 2012 12:05:57 +1200
> Subject: Re: [Stackless] Tasklet cleanup?
> On Sun, May 20, 2012 at 10:29 AM, Sylvain Prat <sylvain.prat at gmail.com> wrote:
>> I'm wondering how tasklets can clean themselves up when they are
>> destroyed due to garbage collection (i.e. when they are not in the
>> runnables and not referenced by any object anymore). Greenlet solves
>> this problem by raising a GreenletExit exception in the greenlet's run
>> function when the greenlet is about to die due to garbage collection.
>> However, in stackless, it seems that no TaskletExit exception is
>> raised when the tasklet is about to die, so we can't simply use a
>> try/finally in the tasklet's callable to clean up resources.
> Greenlet is derived from Stackless, so similarly TaskletExit should be
> raised on a tasklet that is being garbage collected.
>> I tried to wrap my tasklet in a parent object which has the same
>> lifespan as my tasklet and has a __del__ function for cleaning up, but
>> I keep having problems with circular references (the wrapper/parent
>> object also provides the callable of the tasklet, i.e. a bound method)
>> that make the tasklet/parent object uncollectable (circular references
>> : wrapper --> tasklet --> stackless machinery? --> callable stack
>> frame (bound method of wrapper) --> wrapper). Same problem when trying
>> to inherit from tasklet.
>> So, how can I clean up resources in tasklets? (I'm pretty sure I've
>> missed something obvious)
> I've attached two example scripts where a tasklet dies, but does not
> get the TaskletExit raised on it.  This is something Kristjan Valur
> has been working on, but there have been upsides and downsides to the
> different approaches and as I understand it the ideal solution to
> tasklet destruction is yet to be found.
> Kristjan, why is TaskletExit not being raised?  Any ideas?
> Cheers,
> Richard.

Sylvain PRAT
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tasklet_cleanup.py
Type: application/octet-stream
Size: 1061 bytes
Desc: not available
URL: <http://www.stackless.com/pipermail/stackless/attachments/20120520/c616a13c/attachment.obj>

More information about the Stackless mailing list