[Twisted-Python] unlistenTCP not working?

Michael Porter mporter at despammed.com
Thu Jul 24 11:15:28 MDT 2003


Hi,

I'm having a problem with unlistenTCP - it doesn't seem to work if
application.listenTCP was called after the reactor is started. Am I missing
something here or is this a bug? See test code below for demonstration...

def listen(application, port):
    from twisted.web import server, resource
    print "called listen %d" % port
    application.listenTCP(port, server.Site(resource.Resource()))

def unlisten(application, port):
    print "called unlisten %d" % port
    application.unlistenTCP(port)

def test(listenFirst):
    from twisted.python import log
    import sys
    log.startLogging(sys.stdout, 0)
    from twisted.internet import app, reactor
    application = app.Application("test")
    if listenFirst:
        listen(application, 8080)
    else:
        reactor.callLater(0, listen, application, 8080)
    reactor.callLater(5, unlisten, application, 8080)
    application.run(save=0)

If you call test(listenFirst = 1) then all works as expected (log shows it
starts listening immediately and stops after 5 secs). But if you start
listening by scheduling a call after application.run (call test(listenFirst
= 0)) the listenTCP works but when unlisten is called 5 secs later it
doesn't seem to stop listening and nothing appears in the log.

(I'm running on Windows with twisted 1.0.6)

Any ideas? Thanks,

Mike.






More information about the Twisted-Python mailing list