<div dir="ltr">Thanks for your reply!&nbsp; But I think I have to read some source code<br>&nbsp;of twisted to make sure what was happening behind callFromThread.<br><br><div class="gmail_quote">On Tue, Aug 19, 2008 at 11:58 PM, Itamar Shtull-Trauring <span dir="ltr">&lt;<a href="mailto:itamar@itamarst.org">itamar@itamarst.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">On Tue, 2008-08-19 at 20:08 +0800, Peter Cai wrote:<br>
&gt; Hi All,<br>
&gt;<br>
&gt; QUESTION 1 : callFromThread<br>
&gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
&gt;<br>
&gt; I found this code snippet in twisted manual book.<br>
&gt; But I don&#39;t quite get it.<br>
&gt;<br>
&gt; What does &quot;run &#39;notThreadSafe(3)&#39; in the event loop&quot; means?<br>
&gt;<br>
&gt; Does the reactor promise that all those &quot;notThreadSafe&quot; functions<br>
&gt; be called one by one so they won&#39;t interfere each other?<br>
<br>
</div>They will be called in main thread, the one where you did reactor.run()<br>
<div class="Ih2E3d"><br>
&gt; QUESTION 2 : Integrated with a threaded 3rd party library.<br>
&gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
&gt; I have a C library which using a work threaded pool model. &nbsp;It&#39;s<br>
&gt; interface is like this.<br>
&gt;<br>
&gt; &nbsp; &nbsp; void runWorkAsyn(int args, void pcallbackfunc(int));<br>
&gt;<br>
&gt; When runWorkAsyn is called, it dispatch work to a thread in its<br>
&gt; own thread pool and call &#39;pcallbackfunc&#39; in that thread when it&#39;s<br>
&gt; done.<br>
&gt;<br>
&gt; I really got confused by how use this lib from twisted in a thread<br>
&gt; safe way.<br>
&gt; If I use a python callback function as pcallbackfunc and touch the<br>
&gt; reactor from it,<br>
&gt; it might damage the event look as most twisted APIs are not thread<br>
&gt; safe.<br>
<br>
</div>Rather than passing in callable &quot;doSomething&quot; as callback, pass in:<br>
&quot;lambda *args: reactor.callFromThread(doSomething, *args)&quot;.<br>
<br>
<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>科幻小说可能在哲学上是天真的,在道德上是简单的,在美学上是有些主观的,或粗糙的,但是就它最好的方面而言,它似乎触及了人类集体梦想的神经中枢,解放出我们人类这具机器中深藏的某些幻想。<br>
</div>