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"><<a href="mailto:exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a>></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>
>Hi all<br>
><br>
> I just encountered a problem about iocp reactor & callInThread. I<br>
>paste the code following:<br>
><br>
>from twisted.internet import iocpreactor<br>
>iocpreactor.install()<br>
>from twisted.internet import reactor<br>
><br>
>class ThreadTest:<br>
> def __init__(self,name):<br>
> self.count = 0<br>
> self.max = 5<br>
> self.wait = 1<br>
> <a href="http://self.name" target="_blank">self.name</a> = name<br>
><br>
> def __call__(self):<br>
> self.Execute()<br>
><br>
> def Execute(self):<br>
> print <a href="http://self.name" target="_blank">self.name</a>, time.time()<br>
> self.count += 1<br>
> if self.count <self.max:<br>
> reactor.callLater(self.wait, reactor.callInThread,<br>
>self.Execute)<br>
> else:<br>
> print <a href="http://self.name" target="_blank">self.name</a>, "stop"<br>
><br>
>reactor.callInThread(ThreadTest("test"))<br>
><br>
>the problem is every time the print method was invoked, i noticed that<br>
>the difference between current invoke and previous invoke was 2<br>
>seconds. In theory ,it should be one second. When i used the plain<br>
<br>
</div></div>You're calling reactor.callLater from a non-reactor thread. This isn't<br>
supported and will produce unpredictable behavior.<br>
<br>
Jean-Paul<br>
<div class="im">>reactor (which means no iocpreactor), the difference was one second<br>
>which is a correct value.<br>
><br>
>I want to know what makes callInThread so special with iocpreactor?<br>
><br>
>BTW: i used windows 7 & window s2008.<br>
><br>
>Regards<br>
><br>
>gelin yan<br>
><br>
</div><div><div></div><div class="h5">>_______________________________________________<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>
<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>