<div dir="ltr">Thanks for your reply! But I think I have to read some source code<br> 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"><<a href="mailto:itamar@itamarst.org">itamar@itamarst.org</a>></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>
> Hi All,<br>
><br>
> QUESTION 1 : callFromThread<br>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
><br>
> I found this code snippet in twisted manual book.<br>
> But I don't quite get it.<br>
><br>
> What does "run 'notThreadSafe(3)' in the event loop" means?<br>
><br>
> Does the reactor promise that all those "notThreadSafe" functions<br>
> be called one by one so they won'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>
> QUESTION 2 : Integrated with a threaded 3rd party library.<br>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
> I have a C library which using a work threaded pool model. It's<br>
> interface is like this.<br>
><br>
> void runWorkAsyn(int args, void pcallbackfunc(int));<br>
><br>
> When runWorkAsyn is called, it dispatch work to a thread in its<br>
> own thread pool and call 'pcallbackfunc' in that thread when it's<br>
> done.<br>
><br>
> I really got confused by how use this lib from twisted in a thread<br>
> safe way.<br>
> If I use a python callback function as pcallbackfunc and touch the<br>
> reactor from it,<br>
> it might damage the event look as most twisted APIs are not thread<br>
> safe.<br>
<br>
</div>Rather than passing in callable "doSomething" as callback, pass in:<br>
"lambda *args: reactor.callFromThread(doSomething, *args)".<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>