Added try/except for setting signal handlers.

Setting signal handlers from inside a thread is not supported in Python,
but some applications need to run Sleek from a child thread.

SleekXMPP applications that run inside a child thread will NOT be able
to detect SIGHUP or SIGTERM events. Those must be caught and managed by
the main program.
This commit is contained in:
Lance Stout 2010-10-28 10:42:23 -04:00
parent 9c08e56ed0
commit 973890e2c9

View file

@ -199,11 +199,15 @@ class XMLStream(object):
self.auto_reconnect = True self.auto_reconnect = True
self.is_client = False self.is_client = False
if hasattr(signal, 'SIGHUP'): try:
signal.signal(signal.SIGHUP, self._handle_kill) if hasattr(signal, 'SIGHUP'):
if hasattr(signal, 'SIGTERM'): signal.signal(signal.SIGHUP, self._handle_kill)
# Used in Windows if hasattr(signal, 'SIGTERM'):
signal.signal(signal.SIGTERM, self._handle_kill) # Used in Windows
signal.signal(signal.SIGTERM, self._handle_kill)
except:
logging.debug("Can not set interrupt signal handlers. " + \
"SleekXMPP is not running from a main thread.")
def _handle_kill(self, signum, frame): def _handle_kill(self, signum, frame):
""" """