<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle">P {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
</style>
</head>
<body fPStyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">
<p>Hi there.</p>
<p>kill() also causes TaskletExit in regular stackless.</p>
<p>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.</p>
<p> </p>
<p>However,</p>
<p>I have since then be led to believe that this may be overly cautious on our part.</p>
<p>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.</p>
<p> </p>
<p>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.</p>
<p> </p>
<p>K</p>
<div style="FONT-FAMILY: Times New Roman; COLOR: #000000; FONT-SIZE: 16px">
<hr tabindex="-1">
<div style="DIRECTION: ltr" id="divRpF157768"><font color="#000000" size="2" face="Tahoma"><b>Frá:</b> stackless-bounces@stackless.com [stackless-bounces@stackless.com] fyrir hönd Hervé Coatanhay [herve.coatanhay@gmail.com]<br>
<b>Sent:</b> 5. júlí 2012 18:42<br>
<b>To:</b> The Stackless Python Mailing List<br>
<b>Efni:</b> Re: [Stackless] Tasklet cleanup?<br>
</font><br>
</div>
<div></div>
<div>Hi all,
<div><br>
</div>
<div>I was playing with stackless.py from pypy. In that implementation kill() definitely raises an exception:</div>
<div><br>
</div>
<div><a href="https://bitbucket.org/pypy/pypy/src/68e7e825d598/lib_pypy/stackless.py#cl-68" target="_blank">https://bitbucket.org/pypy/pypy/src/68e7e825d598/lib_pypy/stackless.py#cl-68</a></div>
<div><br>
</div>
<div>Just so you know.</div>
<div><br>
</div>
<div>Hervé<br>
<div class="gmail_quote">On Fri, May 25, 2012 at 5:11 AM, Richard Tew <span dir="ltr">
<<a href="mailto:richard.m.tew@gmail.com" target="_blank">richard.m.tew@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="im">On Sun, May 20, 2012 at 10:29 AM, Sylvain Prat <<a href="mailto:sylvain.prat@gmail.com" target="_blank">sylvain.prat@gmail.com</a>> wrote:<br>
</div>
<div class="im">> I tried to wrap my tasklet in a parent object which has the same<br>
> lifespan as my tasklet and has a __del__ function for cleaning up, but<br>
> I keep having problems with circular references (the wrapper/parent<br>
> object also provides the callable of the tasklet, i.e. a bound method)<br>
> that make the tasklet/parent object uncollectable (circular references<br>
> : wrapper --> tasklet --> stackless machinery? --> callable stack<br>
> frame (bound method of wrapper) --> wrapper). Same problem when trying<br>
> to inherit from tasklet.<br>
><br>
> So, how can I clean up resources in tasklets? (I'm pretty sure I've<br>
> missed something obvious)<br>
<br>
</div>
Hi Sylvain,<br>
<br>
Kristjan having clarified that TaskletExit is definitely off the table<br>
for now, I'd like to make the response I should have when you first<br>
posted.  Fix your circular references and __del__ should be fine.<br>
<br>
What I tend to do is use weak references, where applicable, in order<br>
to ensure that nothing keeps a tasklet alive except where I explicitly<br>
want.  There is nothing internal to Stackless which will keep a<br>
tasklet alive without your implicit direction.  If my tasklets are<br>
kept alive and I detect it, then I use gc.get_referrers(tasklet) to<br>
track down why.<br>
<br>
Cheers,<br>
Richard.<br>
<div class="HOEnZb">
<div class="h5"><br>
_______________________________________________<br>
Stackless mailing list<br>
<a href="mailto:Stackless@stackless.com" target="_blank">Stackless@stackless.com</a><br>
<a href="http://www.stackless.com/mailman/listinfo/stackless" target="_blank">http://www.stackless.com/mailman/listinfo/stackless</a><br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</body>
</html>