Browse Source

Timers are started in daemon mode so they don't prevent the app from exiting

shin- 12 years ago
parent
commit
b94c6fd02d
1 changed files with 6 additions and 2 deletions
  1. 6 2
      stackbrew/lib/periodic.py

+ 6 - 2
stackbrew/lib/periodic.py

@@ -9,13 +9,17 @@ def init_task(fn, period, lockfile='/opt/stackbrew/brw.lock', logger=None):
     def periodic(logger):
         if logger is not None:
             logger.info('Periodic task started')
-        threading.Timer(period, periodic, [logger]).start()
+        t = threading.Timer(period, periodic, [logger])
+        t.daemon = True
+        t.start()
         fn()
     if os.path.exists(lockfile):
         raise RuntimeError('Lockfile already present.')
     open(lockfile, 'w').close()
     lockfiles.append(lockfile)
-    threading.Timer(0, periodic, [logger]).start()
+    t = threading.Timer(0, periodic, [logger])
+    t.daemon = True
+    t.start()
 
 
 def clear_lockfiles(lockfiles):