[Twisted-Python] Issue with stopListening

Örjan Reinholdsen Orjan.Reinholdsen at smarttrust.com
Wed May 4 02:23:53 MDT 2005


All,

I have written a Twisted server that will be used as a test server to test the client software ability to gracefully handle server shutdown and thereafter reconnect. For that purpose I need my twisted server to periodically stop listening on ports for a while, and then commence normal operation again. For some reason I don't seem to succeede since the twisted server never seems to stop listening on a port even if I call the stopListening method on the IListeningPort object.

Anyone got a clue to what I'm doing wrong?

Regards
/Örjan

----

[...]

ports = [8007,8008,8009]
listenPorts = []
for port in ports:
   print "Listening on port %d" % port
   listenPorts.append(reactor.listenTCP(port, myFactory)) 

length = len(listenPorts)
ptime = 10
dtime = 5

def Down(ticks):
   print "Stop listening on port %d" % ports[ticks%length] 
   listenPorts[ticks%length].stopListening()
   reactor.callLater(dtime, Up, ticks)

def Up(ticks):
   print "Start listening on port %d" % ports[ticks%length]
   listenPorts[ticks%length].startListening()
   reactor.callLater(ptime, Down, ticks+1)

reactor.callLater(ptime, Down, 0)
reactor.run()




More information about the Twisted-Python mailing list