Author: dmeyer
Date: Sun Feb 26 14:41:43 2006
New Revision: 1227

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

Log:
better shutdown handling

Modified: trunk/base/src/notifier/__init__.py
==============================================================================
--- trunk/base/src/notifier/__init__.py (original)
+++ trunk/base/src/notifier/__init__.py Sun Feb 26 14:41:43 2006
@@ -35,6 +35,7 @@
 import os
 import traceback
 import time
+import signal
 
 # kaa.notifier imports
 from popen import *
@@ -132,10 +133,18 @@
     try:
         notifier.loop()
     except (KeyboardInterrupt, SystemExit):
-        pass
+        try:
+            # This looks stupid, I know that. The problem is that if we have
+            # a KeyboardInterrupt, that flag is still valid somewhere inside
+            # python. The next system call will fail because of that. Since we
+            # don't want a join of threads or similar fail, we use a very short
+            # sleep here. In most cases we won't sleep at all because this 
sleep
+            # fails. But after that everything is back to normal.
+            time.sleep(0.001)
+        except:
+            pass
     except Exception, e:
         pass
-
     running = False
     shutdown()
     if e:
@@ -159,3 +168,11 @@
         notifier.step(*args, **kwargs)
     except (KeyboardInterrupt, SystemExit):
         pass
+
+
+# set signal handler to catch term signal for
+# clean shutdown
+def _signal_handler(signum, frame):
+    shutdown()
+
+signal.signal(signal.SIGTERM, _signal_handler)


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to