<div class="gmail_quote">On Wed, Jan 12, 2011 at 11:32 AM, Glyph Lefkowitz <span dir="ltr">&lt;<a href="mailto:glyph@twistedmatrix.com">glyph@twistedmatrix.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">The reactor doesn&#39;t have a queue of tasks to be completed.  It has sets of various event sources, which it executes in no particular order.</div></blockquote><div><br></div><div>&quot;queue of tasks&quot; was a guess on my part, but I looked through the BaseReactor code and found something like that.  &#39;course, I could easily be reading the code wrong.  How would you describe threadCallQueue?  When I said &quot;tasks&quot;, I meant something akin to &quot;calls&quot;.  That could be confusing---did you interpret &quot;tasks&quot; differently?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>Scheduling a timed event with callLater(0,...) might do what you want, though.</div>
</blockquote></div><br><meta http-equiv="content-type" content="text/html; charset=utf-8"><div class="gmail_quote">Yes.  Thanks!  I see that the callFromThread documentation even recommends using callLater for this behavior. (doh!)</div>
<div class="gmail_quote"><br></div><div class="gmail_quote"><a href="http://twistedmatrix.com/documents/10.2.0/api/twisted.internet.interfaces.IReactorThreads.html#callFromThread">http://twistedmatrix.com/documents/10.2.0/api/twisted.internet.interfaces.IReactorThreads.html#callFromThread</a></div>
<div class="gmail_quote"><div><br></div><div><div>&gt;&gt;&gt; from twisted.internet import reactor</div><div>&gt;&gt;&gt; def foo():</div><div>...     print &quot;foo!&quot;</div><div>... </div><div>&gt;&gt;&gt; def bar():</div>
<div>...     reactor.callLater(0, foo)</div><div>...     print &quot;bar!&quot;</div><div>... </div></div><div><div>&gt;&gt;&gt; reactor.callWhenRunning(bar)</div><div>(&#39;startup&#39;, (&#39;after&#39;, &lt;function bar at 0x2c84320&gt;, (), {}))</div>
<div>&gt;&gt;&gt; reactor.run()</div><div>bar!</div><div>foo!</div></div><div><br></div><div>Interesting that you can substitute callFromThread for callLater(0, ...) in the above code and get the same behavior...</div><div>
<br></div><div>Sorry to prolong the tangent, but I&#39;d like to better understand the differences between callWhenRunning, callFromThread and callLater.  I think reactor.wakeUp() is the one missing piece for me.  How exactly does it work?  Reading the BaseReactor code... callFromThread adds the call to a queue, then calls wakeUp.  IIUC, wakeUp simply runs</div>
<div><br></div><div>self.port.postEvent(0, KEY_WAKEUP, None)</div><div><br></div><div>Does this cause the reactor thread to jump to the front of the queue of threads to be run by python/linux?  If there were no wakeUp in callFromThread, would the call simply be delayed until the thread round-robin got to the reactor thread?  Or, without wakeUp, is it possible the callFromThread call would never be made?</div>
<div><br></div><div>Cheers,</div><div><br></div><div>Jason</div><div><br></div></div>-- <br>Jason Rennie<br>Research Scientist, ITA Software<br>617-714-2645<br><a href="http://www.itasoftware.com/">http://www.itasoftware.com/</a><br>
<br>