From 4eac18a90a7597b0a1fcc100824a42373eaaca72 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 28 Feb 2014 18:54:17 +0100 Subject: add watch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/util.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/util.py b/src/util.py index 936538d..d12d3b2 100644 --- a/src/util.py +++ b/src/util.py @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' import sys +import time import threading import subprocess @@ -35,6 +36,18 @@ def async(target, name = None, group = None): return t +def watch(interval, target): + ''' + Run a function periodically forever + + @param interval:float The number of seconds to sleep between invocatons + @param target:()→void The function + ''' + while True: + target() + time.sleep(interval) + + def spawn(*command): ''' Spawn an external process -- cgit v1.2.3-70-g09d2