This commit is contained in:
Tim Savannah 2017-06-04 04:44:20 -04:00
parent f21d4b4b49
commit 0e43f0b161

View File

@ -19,10 +19,8 @@ LICENSE, otherwise it is available at https://gith
<tr ><td bgcolor="#aa55cc" ><tt >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td >&nbsp;</td>
<td width="100%" ><table width="100%" summary="list" ><tr ><td width="25%" valign="top" ><a href="ctypes.html" >ctypes</a><br />
<a href="os.html" >os</a><br />
</td><td width="25%" valign="top" ><a href="sys.html" >sys</a><br />
<a href="threading.html" >threading</a><br />
</td><td width="25%" valign="top" ><a href="time.html" >time</a><br />
</td><td width="25%" valign="top" ><a href="os.html" >os</a><br />
</td><td width="25%" valign="top" ><a href="threading.html" >threading</a><br />
</td><td width="25%" valign="top" ></td></tr></table></td></tr></table><p >
<table width="100%" cellspacing="0" cellpadding="2" border="0" summary="section" >
<tr bgcolor="#ee77aa" >
@ -46,7 +44,12 @@ LICENSE,&nbsp;otherwise&nbsp;it&nbsp;is&nbsp;available&nbsp;at&nbsp;https://gith
<font color="#000000" face="helvetica, arial" ><a name="JoinThread" >class <strong >JoinThread</strong></a>(<a href="threading.html#Thread" >threading.Thread</a>)</font></td></tr>
<tr bgcolor="#ffc8d8" ><td rowspan="2" ><tt >&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan="2" ><tt ><a href="#JoinThread" >JoinThread</a>&nbsp;-&nbsp;The&nbsp;workhouse&nbsp;that&nbsp;stops&nbsp;the&nbsp;<a href="#StoppableThread" >StoppableThread</a><br />&nbsp;</tt></td></tr>
<td colspan="2" ><tt ><a href="#JoinThread" >JoinThread</a>&nbsp;-&nbsp;The&nbsp;workhouse&nbsp;that&nbsp;stops&nbsp;the&nbsp;<a href="#StoppableThread" >StoppableThread</a>.<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;Takes&nbsp;an&nbsp;exception,&nbsp;and&nbsp;upon&nbsp;being&nbsp;started&nbsp;immediately&nbsp;raises&nbsp;that&nbsp;exception&nbsp;in&nbsp;the&nbsp;current&nbsp;context<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;of&nbsp;the&nbsp;thread's&nbsp;execution&nbsp;(so&nbsp;next&nbsp;line&nbsp;of&nbsp;python&nbsp;gets&nbsp;it,&nbsp;or&nbsp;next&nbsp;call&nbsp;to&nbsp;a&nbsp;python&nbsp;api&nbsp;function&nbsp;in&nbsp;C&nbsp;code&nbsp;).<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;@see&nbsp;<a href="#StoppableThread" >StoppableThread</a>&nbsp;for&nbsp;more&nbsp;details<br />&nbsp;</tt></td></tr>
<tr ><td >&nbsp;</td>
<td width="100%" ><dl ><dt >Method resolution order:</dt>
<dd ><a href="func_timeout.StoppableThread.html#JoinThread" >JoinThread</a></dd>
@ -55,32 +58,18 @@ LICENSE,&nbsp;otherwise&nbsp;it&nbsp;is&nbsp;available&nbsp;at&nbsp;https://gith
</dl>
<hr />
Methods defined here:<br />
<dl ><dt ><a name="JoinThread-__init__" ><strong >__init__</strong></a>(self, otherThread, exception, repeatEvery=2.0)</dt><dd ><tt >This&nbsp;constructor&nbsp;should&nbsp;always&nbsp;be&nbsp;called&nbsp;with&nbsp;keyword&nbsp;arguments.&nbsp;Arguments&nbsp;are:<br />
<dl ><dt ><a name="JoinThread-__init__" ><strong >__init__</strong></a>(self, otherThread, exception, repeatEvery=2.0)</dt><dd ><tt >__init__&nbsp;-&nbsp;Create&nbsp;a&nbsp;<a href="#JoinThread" >JoinThread</a>&nbsp;(don't&nbsp;forget&nbsp;to&nbsp;call&nbsp;.<a href="#JoinThread-start" >start</a>()&nbsp;!&nbsp;)<br />
&nbsp;<br />
*group*&nbsp;should&nbsp;be&nbsp;None;&nbsp;reserved&nbsp;for&nbsp;future&nbsp;extension&nbsp;when&nbsp;a&nbsp;ThreadGroup<br />
class&nbsp;is&nbsp;implemented.<br />
&nbsp;&nbsp;&nbsp;&nbsp;@param&nbsp;otherThread&nbsp;&lt;threading.<a href="threading.html#Thread" >Thread</a>&gt;&nbsp;-&nbsp;A&nbsp;thread<br />
&nbsp;<br />
*target*&nbsp;is&nbsp;the&nbsp;callable&nbsp;object&nbsp;to&nbsp;be&nbsp;invoked&nbsp;by&nbsp;the&nbsp;<a href="#JoinThread-run" >run</a>()<br />
method.&nbsp;Defaults&nbsp;to&nbsp;None,&nbsp;meaning&nbsp;nothing&nbsp;is&nbsp;called.<br />
&nbsp;&nbsp;&nbsp;&nbsp;@param&nbsp;exception&nbsp;&lt;BaseException&gt;&nbsp;-&nbsp;An&nbsp;exception.&nbsp;Should&nbsp;be&nbsp;a&nbsp;BaseException,&nbsp;to&nbsp;prevent&nbsp;"catch&nbsp;Exception&nbsp;as&nbsp;e:&nbsp;continue"&nbsp;type&nbsp;code<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;never&nbsp;being&nbsp;terminated.&nbsp;If&nbsp;such&nbsp;code&nbsp;is&nbsp;unavoidable,&nbsp;you&nbsp;can&nbsp;try&nbsp;setting&nbsp;#repeatEvery&nbsp;to&nbsp;a&nbsp;very&nbsp;low&nbsp;number,&nbsp;like&nbsp;.00001,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and&nbsp;it&nbsp;will&nbsp;hopefully&nbsp;raise&nbsp;within&nbsp;the&nbsp;context&nbsp;of&nbsp;the&nbsp;catch,&nbsp;and&nbsp;be&nbsp;able&nbsp;to&nbsp;break&nbsp;free.<br />
&nbsp;<br />
*name*&nbsp;is&nbsp;the&nbsp;thread&nbsp;name.&nbsp;By&nbsp;default,&nbsp;a&nbsp;unique&nbsp;name&nbsp;is&nbsp;constructed&nbsp;of<br />
the&nbsp;form&nbsp;"<a href="threading.html#Thread" >Thread</a>-N"&nbsp;where&nbsp;N&nbsp;is&nbsp;a&nbsp;small&nbsp;decimal&nbsp;number.<br />
&nbsp;<br />
*args*&nbsp;is&nbsp;the&nbsp;argument&nbsp;tuple&nbsp;for&nbsp;the&nbsp;target&nbsp;invocation.&nbsp;Defaults&nbsp;to&nbsp;().<br />
&nbsp;<br />
*kwargs*&nbsp;is&nbsp;a&nbsp;dictionary&nbsp;of&nbsp;keyword&nbsp;arguments&nbsp;for&nbsp;the&nbsp;target<br />
invocation.&nbsp;Defaults&nbsp;to&nbsp;{}.<br />
&nbsp;<br />
If&nbsp;a&nbsp;subclass&nbsp;overrides&nbsp;the&nbsp;constructor,&nbsp;it&nbsp;must&nbsp;make&nbsp;sure&nbsp;to&nbsp;invoke<br />
the&nbsp;base&nbsp;class&nbsp;constructor&nbsp;(<a href="threading.html#Thread" >Thread</a>.<a href="#JoinThread-__init__" >__init__</a>())&nbsp;before&nbsp;doing&nbsp;anything<br />
else&nbsp;to&nbsp;the&nbsp;thread.</tt></dd></dl>
&nbsp;&nbsp;&nbsp;&nbsp;@param&nbsp;repeatEvery&nbsp;&lt;float&gt;&nbsp;Default&nbsp;2.0&nbsp;-&nbsp;After&nbsp;starting,&nbsp;the&nbsp;given&nbsp;exception&nbsp;is&nbsp;immediately&nbsp;raised.&nbsp;Then,&nbsp;every&nbsp;#repeatEvery&nbsp;seconds,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;it&nbsp;is&nbsp;raised&nbsp;again,&nbsp;until&nbsp;the&nbsp;thread&nbsp;terminates.</tt></dd></dl>
<dl ><dt ><a name="JoinThread-run" ><strong >run</strong></a>(self)</dt><dd ><tt >Method&nbsp;representing&nbsp;the&nbsp;thread's&nbsp;activity.<br />
&nbsp;<br />
You&nbsp;may&nbsp;override&nbsp;this&nbsp;method&nbsp;in&nbsp;a&nbsp;subclass.&nbsp;The&nbsp;standard&nbsp;<a href="#JoinThread-run" >run</a>()&nbsp;method<br />
invokes&nbsp;the&nbsp;callable&nbsp;object&nbsp;passed&nbsp;to&nbsp;the&nbsp;object's&nbsp;constructor&nbsp;as&nbsp;the<br />
target&nbsp;argument,&nbsp;if&nbsp;any,&nbsp;with&nbsp;sequential&nbsp;and&nbsp;keyword&nbsp;arguments&nbsp;taken<br />
from&nbsp;the&nbsp;args&nbsp;and&nbsp;kwargs&nbsp;arguments,&nbsp;respectively.</tt></dd></dl>
<dl ><dt ><a name="JoinThread-run" ><strong >run</strong></a>(self)</dt><dd ><tt >run&nbsp;-&nbsp;The&nbsp;thread&nbsp;main.&nbsp;Will&nbsp;attempt&nbsp;to&nbsp;stop&nbsp;and&nbsp;join&nbsp;the&nbsp;attached&nbsp;thread.</tt></dd></dl>
<hr />
Methods inherited from <a href="threading.html#Thread" >threading.Thread</a>:<br />
@ -175,7 +164,24 @@ initial&nbsp;name&nbsp;is&nbsp;set&nbsp;by&nbsp;the&nbsp;constructor.</tt></dd>
<font color="#000000" face="helvetica, arial" ><a name="StoppableThread" >class <strong >StoppableThread</strong></a>(<a href="threading.html#Thread" >threading.Thread</a>)</font></td></tr>
<tr bgcolor="#ffc8d8" ><td rowspan="2" ><tt >&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan="2" ><tt ><a href="#StoppableThread" >StoppableThread</a>&nbsp;-&nbsp;A&nbsp;thread&nbsp;that&nbsp;can&nbsp;be&nbsp;stopped&nbsp;by&nbsp;forcing&nbsp;an&nbsp;exception&nbsp;in&nbsp;the&nbsp;execution&nbsp;context.<br />&nbsp;</tt></td></tr>
<td colspan="2" ><tt ><a href="#StoppableThread" >StoppableThread</a>&nbsp;-&nbsp;A&nbsp;thread&nbsp;that&nbsp;can&nbsp;be&nbsp;stopped&nbsp;by&nbsp;forcing&nbsp;an&nbsp;exception&nbsp;in&nbsp;the&nbsp;execution&nbsp;context.<br />
&nbsp;<br />
&nbsp;&nbsp;This&nbsp;works&nbsp;both&nbsp;to&nbsp;interrupt&nbsp;code&nbsp;that&nbsp;is&nbsp;in&nbsp;C&nbsp;or&nbsp;in&nbsp;python&nbsp;code,&nbsp;at&nbsp;either&nbsp;the&nbsp;next&nbsp;call&nbsp;to&nbsp;a&nbsp;python&nbsp;function,<br />
&nbsp;&nbsp;&nbsp;or&nbsp;the&nbsp;next&nbsp;line&nbsp;in&nbsp;python&nbsp;code.<br />
&nbsp;<br />
It&nbsp;is&nbsp;recommended&nbsp;that&nbsp;if&nbsp;you&nbsp;call&nbsp;stop&nbsp;(&nbsp;@see&nbsp;<a href="#StoppableThread" >StoppableThread</a>.stop&nbsp;)&nbsp;that&nbsp;you&nbsp;use&nbsp;an&nbsp;exception&nbsp;that&nbsp;inherits&nbsp;BaseException,&nbsp;to&nbsp;ensure&nbsp;it&nbsp;likely&nbsp;isn't&nbsp;caught.<br />
&nbsp;<br />
&nbsp;Also,&nbsp;beware&nbsp;unmarked&nbsp;exception&nbsp;handlers&nbsp;in&nbsp;your&nbsp;code.&nbsp;Code&nbsp;like&nbsp;this:<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;True:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doSomething()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;except:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue<br />
&nbsp;<br />
will&nbsp;never&nbsp;be&nbsp;able&nbsp;to&nbsp;abort,&nbsp;because&nbsp;the&nbsp;exception&nbsp;you&nbsp;raise&nbsp;is&nbsp;immediately&nbsp;caught.<br />
&nbsp;<br />
The&nbsp;exception&nbsp;is&nbsp;raised&nbsp;over&nbsp;and&nbsp;over,&nbsp;with&nbsp;a&nbsp;specifed&nbsp;delay&nbsp;(default&nbsp;2.0&nbsp;seconds)<br />&nbsp;</tt></td></tr>
<tr ><td >&nbsp;</td>
<td width="100%" ><dl ><dt >Method resolution order:</dt>
<dd ><a href="func_timeout.StoppableThread.html#StoppableThread" >StoppableThread</a></dd>
@ -184,7 +190,7 @@ initial&nbsp;name&nbsp;is&nbsp;set&nbsp;by&nbsp;the&nbsp;constructor.</tt></dd>
</dl>
<hr />
Methods defined here:<br />
<dl ><dt ><a name="StoppableThread-stop" ><strong >stop</strong></a>(self, exception)</dt><dd ><tt >Stops&nbsp;the&nbsp;thread&nbsp;by&nbsp;raising&nbsp;a&nbsp;given&nbsp;exception.<br />
<dl ><dt ><a name="StoppableThread-stop" ><strong >stop</strong></a>(self, exception, raiseEvery=2.0)</dt><dd ><tt >Stops&nbsp;the&nbsp;thread&nbsp;by&nbsp;raising&nbsp;a&nbsp;given&nbsp;exception.<br />
&nbsp;<br />
@param&nbsp;exception&nbsp;&lt;Exception&gt;&nbsp;-&nbsp;Exception&nbsp;to&nbsp;throw.&nbsp;Likely,&nbsp;you&nbsp;want&nbsp;to&nbsp;use&nbsp;something<br />
&nbsp;&nbsp;that&nbsp;inherits&nbsp;from&nbsp;BaseException&nbsp;(so&nbsp;except&nbsp;Exception&nbsp;as&nbsp;e:&nbsp;continue;&nbsp;isn't&nbsp;a&nbsp;problem)</tt></dd></dl>