From d809038869a5fd3502e25d73f9c0b62bd3ac461c Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Thu, 24 Nov 2016 21:26:12 +0200 Subject: [PATCH] add facility to shutdown client from external thread --- jmclient/client_protocol.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/jmclient/client_protocol.py b/jmclient/client_protocol.py index 4e7b004..f70d93d 100644 --- a/jmclient/client_protocol.py +++ b/jmclient/client_protocol.py @@ -2,6 +2,7 @@ from __future__ import print_function from twisted.python.log import startLogging, err from twisted.internet import protocol, reactor +from twisted.internet.task import LoopingCall from twisted.protocols import amp from twisted.internet.protocol import ClientFactory from twisted.internet.endpoints import TCP4ClientEndpoint @@ -39,6 +40,16 @@ class JMTakerClientProtocol(amp.AMP): else: self.nick_priv = nick_priv + self.shutdown_requested = False + lc = LoopingCall(self.checkForShutdown) + lc.start(0.2) + + def checkForShutdown(self): + if self.shutdown_requested: + jlog.info("Client shutdown was requested, complying.") + self.shutdown_requested = False + reactor.stop() + def checkClientResponse(self, response): """A generic check of client acceptance; any failure is considered criticial.