From 11264fe0a8d1224b9a185fc0439359477ef9c3cc Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Wed, 20 Oct 2010 17:30:12 -0700 Subject: capture SIGHUP and SIGTERM (windows) and disconnect; also testall no longer loads string26 with python3 --- sleekxmpp/xmlstream/xmlstream.py | 14 +++++++++++++- testall.py | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index 3459f507..41ee8329 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -16,6 +16,7 @@ import sys import threading import time import types +import signal try: import queue except ImportError: @@ -195,6 +196,17 @@ class XMLStream(object): self.auto_reconnect = True self.is_client = False + signal.signal(signal.SIGHUP, self._handle_kill) + signal.signal(signal.SIGTERM, self._handle_kill) # used in Windows + + def _handle_kill(self, signum, frame): + """ + Capture kill event and disconnect cleanly after first + spawning the "killed" event. + """ + self.event("killed", direct=True) + self.disconnect() + def new_id(self): """ Generate and return a new stream ID in hexadecimal form. @@ -710,7 +722,7 @@ class XMLStream(object): if depth == 0: # The stream's root element has closed, # terminating the stream. - logging.debug("Ending read XML loop") + logging.debug("End of stream recieved") self.stream_end_event.set() return False elif depth == 1: diff --git a/testall.py b/testall.py index d3d049e6..2f980654 100644 --- a/testall.py +++ b/testall.py @@ -13,7 +13,7 @@ class testoverall(unittest.TestCase): if sys.version_info < (3,0): self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn'), quiet=True)) else: - self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn|.*26\Z'), quiet=True)) + self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn|.*26.*'), quiet=True)) def testTabNanny(self): """Invoking the tabnanny""" -- cgit v1.2.3