[Stackless] Tasklet cleanup?

Kristján Valur Jónsson kristjan at ccpgames.com
Mon Jul 9 11:10:46 CEST 2012


Hi there.

kill() also causes TaskletExit in regular stackless.

The problem, as described, is that for garbage collection, it could be unsafe in some circumstances to raise an exception, because task switching in the middle of garbage collection could have unforeseen circumstances.



However,

I have since then be led to believe that this may be overly cautious on our part.

In PyPy in particular, they do not tread as carefully as cpython when it comes to garbage collection.  There, all objects even with __del__ finalizers are clenaed up during garbage collection and any errors that may occur (due to unexpected cleanup order) simply ignored.



The problems in stackless were more devious and harder to debug because killin a tasklet causes immediate task switching and this may have a cascading effect, causing other tasklets to run and so on.  I think we can tackle this better.



K

________________________________
Frá: stackless-bounces at stackless.com [stackless-bounces at stackless.com] fyrir hönd Hervé Coatanhay [herve.coatanhay at gmail.com]
Sent: 5. júlí 2012 18:42
To: The Stackless Python Mailing List
Efni: Re: [Stackless] Tasklet cleanup?

Hi all,

I was playing with stackless.py from pypy. In that implementation kill() definitely raises an exception:

https://bitbucket.org/pypy/pypy/src/68e7e825d598/lib_pypy/stackless.py#cl-68

Just so you know.

Hervé
On Fri, May 25, 2012 at 5:11 AM, Richard Tew <richard.m.tew at gmail.com<mailto:richard.m.tew at gmail.com>> wrote:
On Sun, May 20, 2012 at 10:29 AM, Sylvain Prat <sylvain.prat at gmail.com<mailto: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)

Hi Sylvain,

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.

Cheers,
Richard.

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stackless.com/pipermail/stackless/attachments/20120709/2d4eb3cf/attachment.html>


More information about the Stackless mailing list