[Twisted-Python] oddness in gtk reactor compred to wx and plain reactor

David E. Konerding dekonerding at lbl.gov
Tue Feb 24 13:30:49 MST 2004


Hi,

I have been experience a weird problem with the gtk reactor.  I've got a 
simple test case which seems to reproduce the problem, so I'm checking 
with the mailing list to understand if everything is going on properly.
Here's the test code.  I wasn't sure whether the log. calls are 
thread-safe, but I've noticed the same problem with
Python's logging package.  Using the wxPython or plain reactor seems to 
work as expected: messages from the TestThingy are spewed at about 
0.1/sec, while with gtk, messages only come every 2 seconds if at all.

import time, sys, logging

from twisted.internet import gtk2reactor
gtk2reactor.install()

## from wxPython.wx import *
## from twisted.internet import wxsupport


from twisted.internet import reactor

from twisted.python import threadable
threadable.init()

from twisted.python import log
log.startLogging(sys.stdout)

from twisted.internet import app
from twisted.manhole import telnet
from twisted.application import strports


## For testing with wx reactor
## class myWxApp(wxApp):
##     def OnInit(self):
##         return True


## mywxAppInstance = myWxApp(0)
## wxsupport.install(mywxAppInstance)

class TestThingy:
    def __init__(self):
        log.err("TestThingy created")

    def run(self):
        log.err("TestThingy run")
        for i in range(10):
            log.err("TestThingy message")
            time.sleep(0.1)
        log.err("TestThingy done")
       
       
class ThingyManager:
    def __init__(self):
        log.err("ThingyManager")
       
    def submitThingy(self):
        log.err("ThingyManager submitting")
        f = TestThingy()
        log.err("ThingyManager created")
        reactor.callInThread(f.run)
        log.err("ThingyManager calledInThread")

def timer(*args):
    log.err("Timer: %d" % time.time())
    reactor.callLater(1, timer)

log.err("Starting")
t = ThingyManager()
log.err("Starting timer")
reactor.callLater(0, timer)
log.err("Submitting transfer")
reactor.callLater(3, t.submitThingy)
log.err("Running reactor")
reactor.run()
## for starting the wx reactor
##reactor.run(installSignalHandlers=0)
log.err("Reactor done")






More information about the Twisted-Python mailing list