浏览代码

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

shin- 12 年之前
父节点
当前提交
b94c6fd02d
共有 1 个文件被更改,包括 6 次插入2 次删除
  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):