Skip to content
Browse files

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.
  • Loading branch information...
1 parent 9c08e56 commit 973890e2c913c466b3dfb48c8bd01c28a7baf6c5 @legastero legastero committed Oct 28, 2010
Showing with 9 additions and 5 deletions.
  1. +9 −5 sleekxmpp/xmlstream/xmlstream.py
View
14 sleekxmpp/xmlstream/xmlstream.py
@@ -199,11 +199,15 @@ def __init__(self, socket=None, host='', port=0):
self.auto_reconnect = True
self.is_client = False
- if hasattr(signal, 'SIGHUP'):
- signal.signal(signal.SIGHUP, self._handle_kill)
- if hasattr(signal, 'SIGTERM'):
- # Used in Windows
- signal.signal(signal.SIGTERM, self._handle_kill)
+ try:
+ if hasattr(signal, 'SIGHUP'):
+ signal.signal(signal.SIGHUP, self._handle_kill)
+ if hasattr(signal, 'SIGTERM'):
+ # 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):
"""

0 comments on commit 973890e

Please sign in to comment.
Something went wrong with that request. Please try again.