Commits

fab31 committed 4a1380d

Now should abort cleanly if interrupted

  • Participants
  • Parent commits ec2578b
  • Tags STABLE

Comments (0)

Files changed (2)

zicbee/core/commands/serve.py

     # chdir to serve files at the right place
     import web
     import socket
+    import signal
     import os, sys
     from zicbee_lib.config import config
     from zicbee_lib.debug import debug_enabled, DEBUG
     from zicbee_lib.resources import resource_filename
-    from zicbee.core.httpdb import web_db_index
+    from zicbee.core.httpdb import web_db_index, kill_server
+
+    def abort():
+        kill_server()
+        raise SystemExit()
+
+    signal.signal(signal.SIGINT, abort)
+
     if not pure:
         # let's do webplayer
         try:
             DEBUG()
             pure = True
 
-
     try:
         p = os.path.dirname(resource_filename('zicbee.ui.web', 'static'))
         os.chdir( p )

zicbee/core/httpdb.py

 else:
     web.config.debug = None
 
+def kill_server():
+    zshell.songs.close()
+    try:
+        from zicbee.core.httpplayer import webplayer
+        webplayer.player.close()
+    except:
+        pass
+
 
 # Set default headers & go to templates directory
 web.ctx.headers = [('Content-Type', 'text/html; charset=utf-8'), ('Expires', 'Thu, 01 Dec 1994 16:00:00 GMT')]
         Returns:
             "Aaaah!"
         """
-        zshell.songs.close()
-        try:
-            from zicbee.core.httpplayer import webplayer
-            webplayer.player.close()
-        except:
-            pass
+        kill_server()
         yield 'Aaaah!'
         raise SystemExit()