Unsuccesfull attempts at clean quit on exceptions that fall through

Mon, 22 Jan 2018 00:12:51 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 22 Jan 2018 00:12:51 +0000
changeset 46
ecb41072a1b7
parent 45
aa2a95dc6093
child 47
305de2297fde

Unsuccesfull attempts at clean quit on exceptions that fall through

backup.py file | annotate | diff | comparison | revisions
borgend.py file | annotate | diff | comparison | revisions
ui.py file | annotate | diff | comparison | revisions
--- a/backup.py	Sun Jan 21 23:52:35 2018 +0000
+++ b/backup.py	Mon Jan 22 00:12:51 2018 +0000
@@ -344,14 +344,14 @@
         with self.lock:
             if self.borg_instance:
                 self.borg_instance.terminate()
-            thread_log=self.thread_log
-            thread_res=self.thread_res
+            #thread_log=self.thread_log
+            #thread_res=self.thread_res
 
-        if thread_log:
-            thread_log.terminate()
+        #if thread_log:
+        #    thread_log.terminate()
 
-        if thread_res:
-            thread_res.terminate()
+        #if thread_res:
+        #    thread_res.terminate()
 
 
     def join(self):
--- a/borgend.py	Sun Jan 21 23:52:35 2018 +0000
+++ b/borgend.py	Mon Jan 22 00:12:51 2018 +0000
@@ -64,6 +64,7 @@
 if __name__=="__main__":
     # Parse args. Let argparse handle errors/exit if there are any
     args= do_args()
+    tray = None
 
     try:
         args=do_args()
@@ -85,22 +86,30 @@
         backupconfigs=config.settings['backups']
         backups=[None]*len(backupconfigs);
 
-        for i in range(len(backupconfigs)):
-            logger.info('Setting up backup set %d' % i)
-            backups[i]=Backup(i, backupconfigs[i])
-            backups[i].schedule()
+        try:
+            for i in range(len(backupconfigs)):
+                logger.info('Setting up backup set %d' % i)
+                backups[i]=Backup(i, backupconfigs[i])
+                backups[i].schedule()
 
-        if args.notray or platform.system()!='Darwin':
-            pass
-        else:
-            from ui import BorgendTray
-            tray=BorgendTray(backups);
-            tray.run()
-
+            if args.notray or platform.system()!='Darwin':
+                pass
+            else:
+                from ui import BorgendTray
+                tray=BorgendTray(backups);
+                tray.run()
+        finally:
+            for i in range(len(backups)):
+                if backups[i]:
+                    backups[i].abort()
+            backups=[]
     except Exception as err:
         utils.log_exception(logger, err, detail='Exiting')
-        logging.shutdown()
-        os.exit()
+        if tray:
+            tray.quit()
+        else:
+            logging.shutdown()
+            #sys.exit()
 
     #
     # This shit is fucked, disables ^C etc., and threading doesn't seem to help
--- a/ui.py	Sun Jan 21 23:52:35 2018 +0000
+++ b/ui.py	Mon Jan 22 00:12:51 2018 +0000
@@ -163,7 +163,7 @@
         menu.append(menu_log)
 
         if not settings['no_quit_menu_entry']:
-            menu_quit=rumps.MenuItem("Quit...", callback=self.my_quit)
+            menu_quit=rumps.MenuItem("Quit...", callback=lambda _: self.quit())
             menu.append(menu_quit)
 
         return menu, state
@@ -198,7 +198,7 @@
             notification_workaround(borgend.appname_stylised,
                                     msgid, errorlog['message'])
 
-    def my_quit(self, _):
+    def quit(self):
         logging.shutdown()
         rumps.quit_application()
 

mercurial