diff options
author | Lance Stout <lancestout@gmail.com> | 2010-10-28 10:42:23 -0400 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2010-10-28 10:42:23 -0400 |
commit | 973890e2c913c466b3dfb48c8bd01c28a7baf6c5 (patch) | |
tree | 049f9b8dc384745870eded586c4f8006c4ee3ce5 /sleekxmpp/xmlstream | |
parent | 9c08e56ed04ff38422dfadcbf8cc18da03c3c399 (diff) | |
download | slixmpp-973890e2c913c466b3dfb48c8bd01c28a7baf6c5.tar.gz slixmpp-973890e2c913c466b3dfb48c8bd01c28a7baf6c5.tar.bz2 slixmpp-973890e2c913c466b3dfb48c8bd01c28a7baf6c5.tar.xz slixmpp-973890e2c913c466b3dfb48c8bd01c28a7baf6c5.zip |
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.
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r-- | sleekxmpp/xmlstream/xmlstream.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index 630e68bf..cc192715 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -199,11 +199,15 @@ class XMLStream(object): 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): """ |