[Twisted-Python] Restarting a reactor listener

Travis Vachon tvachon at gmail.com
Wed Aug 2 19:12:49 EDT 2006

Hi Ian

I ran into this just recently, but am not entirely certain I found the best
solution. I needed to be able to switch the port the reactor was listening
on without restarting the reactor. Here's how I did it:

     def startListener(self, port, interface=""):

        self.iListeningPort = reactor.listenTCP(
    def restartListener(self, port, interface=""):

        self.startListener(port, interface)

I'm not sure if doing this will have any unintended side-effects, but so far
it seems to have done the trick. If someone else on the list could confirm
this does what I think it does (and what Ian is looking for) that would be



On 8/1/06, ian.parker at facilita.co.uk <ian.parker at facilita.co.uk> wrote:
> I have created an internet server that is started in a thread from a
> Python QT GUI.
> I can call reactor.stop() and sucessfully get notified of shutdown and the
> run thread terminates, the TCP/IP listen port is closed.
> When I restart it by calling reactor.listenTCP() and  reactor.run(installSignalHandlers=0)
> a second time I find that things don't work correctly. e.g. TCP calls are
> accepted and my protocol.dataReceived() is called but then calling
> reactor.callInThread(self.blockingMethod, data) does nothing. Also calling
> stop() a second time does not stop the  running reactor thread or terminate
> the TCP listener.
> I have tried numerous options, and have been careful to avoid any
> conflicts with the GUI threads. It appears that the reactor is not being
> restarted correctly after stop() and a second run().
> What I need is to stop and re-start the listenTCP.  Is there a way to do
> this?
> Thanks,
> Ian
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20060802/ae92542d/attachment.htm 

More information about the Twisted-Python mailing list