[Twisted-Python] Issue with stopListening
Eric Mangold
teratorn at twistedmatrix.com
Wed May 4 06:28:12 MDT 2005
On Wed, 04 May 2005 18:23:53 +1000, Örjan Reinholdsen
<Orjan.Reinholdsen at smarttrust.com> wrote:
> 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?
stopListening() may return a deferred, in which case you'll need to wait
for it to fire before you can be sure that Twisted has stopped listening.
Since you have multiple ports a DeferredList may help you here.
Perhaps that is the problem?
-Eric
>
> 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()
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
More information about the Twisted-Python
mailing list