[Twisted-Python] Sending a "good-bye message" before closing a connection

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Wed Nov 23 07:34:59 EST 2011

On 10:13 am, albert.brandl at weiermayer.com wrote:
>On Fri, Nov 18, 2011 at 08:31:18AM -0500, Itamar Turner-Trauring wrote:
>>Presumably there is a method somewhere that decides to close the
>>connection down:
>>    def timeToShutdown(self):
>>        self.transport.loseConnection()
>Actually, I hoped that I'd find such a method in the framework. When 
>twistd daemon is shut down, it has to close all connections, and it 
>have been nice if there were a hook that could be overridden.
>But AFAICT, the respective code is buried inside the BaseConnector 
>and I'd rather leave it alone :-).
>Anyway - it should be possible to send some kind of message to the 
>in the init script before shutting it down.

The shutdown hook provided is IService.stopService.  You can add your 
custom shutdown logic there, and attach your service to the 
Application/Service hierarchy.


More information about the Twisted-Python mailing list