Hi all  <br>I modified my code as<br><br>reactor.callFromThread(reactor.callLater, self.wait, reactor.callInThread, self.Execute)<br><br>based on your comments.<br><br>now the problem have been solved. Thanks your guys. I appreciate your help.<br>
<br>Regards<br><br>gelin yan<br><br><div class="gmail_quote">On Mon, May 16, 2011 at 12:29 AM,  <span dir="ltr">&lt;<a href="mailto:exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5">On 04:10 pm, <a href="mailto:dynamicgl@gmail.com">dynamicgl@gmail.com</a> wrote:<br>
&gt;Hi all<br>
&gt;<br>
&gt;     I just encountered a problem about iocp reactor &amp; callInThread. I<br>
&gt;paste the code following:<br>
&gt;<br>
&gt;from twisted.internet import iocpreactor<br>
&gt;iocpreactor.install()<br>
&gt;from twisted.internet import reactor<br>
&gt;<br>
&gt;class ThreadTest:<br>
&gt;    def __init__(self,name):<br>
&gt;        self.count = 0<br>
&gt;        self.max = 5<br>
&gt;        self.wait = 1<br>
&gt;        <a href="http://self.name" target="_blank">self.name</a> = name<br>
&gt;<br>
&gt;    def __call__(self):<br>
&gt;        self.Execute()<br>
&gt;<br>
&gt;    def Execute(self):<br>
&gt;        print <a href="http://self.name" target="_blank">self.name</a>, time.time()<br>
&gt;        self.count += 1<br>
&gt;        if self.count &lt;self.max:<br>
&gt;            reactor.callLater(self.wait, reactor.callInThread,<br>
&gt;self.Execute)<br>
&gt;        else:<br>
&gt;            print <a href="http://self.name" target="_blank">self.name</a>, &quot;stop&quot;<br>
&gt;<br>
&gt;reactor.callInThread(ThreadTest(&quot;test&quot;))<br>
&gt;<br>
&gt;the problem is every time the print method was invoked, i noticed that<br>
&gt;the difference between current invoke and previous invoke was 2<br>
&gt;seconds. In theory ,it should be one second. When i used the plain<br>
<br>
</div></div>You&#39;re calling reactor.callLater from a non-reactor thread.  This isn&#39;t<br>
supported and will produce unpredictable behavior.<br>
<br>
Jean-Paul<br>
<div class="im">&gt;reactor (which means no iocpreactor), the difference was one second<br>
&gt;which is a correct value.<br>
&gt;<br>
&gt;I want to know what makes callInThread so special with iocpreactor?<br>
&gt;<br>
&gt;BTW: i used windows 7 &amp; window s2008.<br>
&gt;<br>
&gt;Regards<br>
&gt;<br>
&gt;gelin yan<br>
&gt;<br>
</div><div><div></div><div class="h5">&gt;_______________________________________________<br>
&gt;Twisted-Python mailing list<br>
&gt;<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
&gt;<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><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>
</div></div></blockquote></div><br>