[Stackless] Tasklet cleanup?
richard.m.tew at gmail.com
Fri May 25 05:11:48 CEST 2012
On Sun, May 20, 2012 at 10:29 AM, Sylvain Prat <sylvain.prat at gmail.com> wrote:
> 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)
Kristjan having clarified that TaskletExit is definitely off the table
for now, I'd like to make the response I should have when you first
posted. Fix your circular references and __del__ should be fine.
What I tend to do is use weak references, where applicable, in order
to ensure that nothing keeps a tasklet alive except where I explicitly
want. There is nothing internal to Stackless which will keep a
tasklet alive without your implicit direction. If my tasklets are
kept alive and I detect it, then I use gc.get_referrers(tasklet) to
track down why.
More information about the Stackless