<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1389721476;
        mso-list-type:hybrid;
        mso-list-template-ids:-723210898 134807575 134807577 134807579 134807567 134807577 134807579 134807567 134807577 134807579;}
@list l0:level1
        {mso-level-number-format:alpha-lower;
        mso-level-text:"%1\)";
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">I’ve been thinking some more about this.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">It should be ok to kill a tasklet that hasn’t run yet.  And killing a dead one should be a no-op.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Rather than making “kill” have special semantics, how about just applying that rule?  An exception sent to a tasklet that hasn´t run yet just disappears and the tasklet dies.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">An exception sent to a dead tasklet just disappears.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">I think these are sensible semantics.  In my opinion, it was a mistake to design stackless such that uncought tasklet exceptions were sent to the main tasklet.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">K<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:EN-GB">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:EN-GB"> stackless-bounces@stackless.com
 [mailto:stackless-bounces@stackless.com] <b>On Behalf Of </b>Kristján Valur Jónsson<br>
<b>Sent:</b> 4. apríl 2013 09:45<br>
<b>To:</b> The Stackless Python Mailing List (stackless@stackless.com)<br>
<b>Subject:</b> [Stackless] added tasklet.throw<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="IS">Yesterday I checked in a new feature to stackless.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IS">Tasklets now have a new function, „throw“, which enhances the already present tasklet.raise_exception().<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IS"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="IS">The docstrings:<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:#A31515">"tasklet.throw(exc, val, tb, immediate=True) -- raise an exception for the tasklet.\n\</span><span style="font-size:9.5pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:#A31515">             'exc', 'val' and 'tb' have the same semantics as Python's 'raise' statement.\n\</span><span style="font-size:9.5pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:#A31515">             If 'immediate' is True, the tasklet is immediately activated, otherwise, it is\n\</span><span style="font-size:9.5pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:#A31515">             merely made runnable"</span><span style="font-size:9.5pt;font-family:Consolas">);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IS"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="IS"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="IS">This brings two new features:<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span lang="IS"><span style="mso-list:Ignore">a)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span lang="IS">unifies the argument semantics.  It now takes the same three arguments as a python „raise“ expression, just like channel.send_throw() already does.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span lang="IS"><span style="mso-list:Ignore">b)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span lang="IS">It allows the target to be scheduled, rather than invoked immediately.  This is useful in frameworks, for example to send a timeout error to a tasklet without interrupting regular scheduling.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span lang="IS"><span style="mso-list:Ignore">c)<span style="font:7.0pt "Times New Roman"">      
</span></span></span><![endif]><span lang="IS">if the exception cannot be sent because the target is dead/not yet running, then a RuntimeError is raised. 
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IS"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="IS"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="IS">item c) is the reason we can‘t let the existing kill and raise_exception methods use this.  They have the confusing property that if the target is dead or not running yet, the error will be raised on the main tasklet instead. 
 I actually think that this is a pretty bad idea.  I wonder if anyone is depending on this?  If not, I can make kill and raise_exception a special case of the new one.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IS"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="IS">(channel.send_throw() is also a fairly recent addition.  An improvement on channel.send_exception() it allows the user to send an existing excetption instance, and a traceback, over the channel.  It is particularly the sending
 of tracebacks which is useful when handling errors.)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IS">K<o:p></o:p></span></p>
</div>
</div>
</body>
</html>