[Twisted-Python] a problem about iocp and callInThread

Dfgqq Dfgqq dynamicgl at gmail.com
Sun May 15 12:10:01 EDT 2011


Hi all

     I just encountered a problem about iocp reactor & callInThread. I
paste the code following:

from twisted.internet import iocpreactor
iocpreactor.install()
from twisted.internet import reactor

class ThreadTest:
    def __init__(self,name):
        self.count = 0
        self.max = 5
        self.wait = 1
        self.name = name

    def __call__(self):
        self.Execute()

    def Execute(self):
        print self.name, time.time()
        self.count += 1
        if self.count <self.max:
            reactor.callLater(self.wait, reactor.callInThread, self.Execute)
        else:
            print self.name, "stop"

reactor.callInThread(ThreadTest("test"))

the problem is every time the print method was invoked, i noticed that
the difference between current invoke and previous invoke was 2
seconds. In theory ,it should be one second. When i used the plain
reactor (which means no iocpreactor), the difference was one second
which is a correct value.

I want to know what makes callInThread so special with iocpreactor?

BTW: i used windows 7 & window s2008.

Regards

gelin yan



More information about the Twisted-Python mailing list