Author: dmeyer
Date: Fri Mar 16 15:05:56 2007
New Revision: 2563

Modified:
   trunk/base/src/notifier/__init__.py

Log:
make it possible to import kaa from a thread

Modified: trunk/base/src/notifier/__init__.py
==============================================================================
--- trunk/base/src/notifier/__init__.py (original)
+++ trunk/base/src/notifier/__init__.py Fri Mar 16 15:05:56 2007
@@ -34,9 +34,9 @@
 import sys
 import logging
 import os
-import traceback
 import time
 import signal
+import threading
 import atexit
 
 # kaa.notifier imports
@@ -159,15 +159,7 @@
         raise SystemExit
 
 
-# set signal handler to catch term signal for
-# clean shutdown
-def _signal_handler(signum, frame):
-    shutdown()
-
-# catch SIGTERM
-signal.signal(signal.SIGTERM, _signal_handler)
-
-def _shutdown_check():
+def _shutdown_check(*args):
     # Helper function to shutdown kaa on system exit
     # The problem is that pytgtk just exits python and
     # does not simply return from the main loop and kaa
@@ -184,5 +176,11 @@
             running = False
         shutdown()
 
+# # catch SIGTERM if possible for a clean shutdown
+if threading.enumerate()[0] == threading.currentThread():
+    signal.signal(signal.SIGTERM, _shutdown_check)
+else:
+    log.info('kaa imported from thread, disable SIGTERM handler')
+    
 # check to make sure we really call our shutdown function
 atexit.register(_shutdown_check)

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to