b045294f3cd1 v1.0.2

Fix cutoff thrashing/skipping

This fixes two main bugs I've been seeing sporadically for a while:

1. `peat` would sometimes "thrash" and run the command a bunch of times in a row
   even though nothing was changing between runs.
2. Other times `peat` would miss a change and I'd have to manually save a file
   again to trigger another run.

Neither of these were too annoying to work around, so I haven't gotten around to
fixing them until now.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 23 Feb 2016 13:41:50 +0000
parents 7a725f724e08
children 2d1174aea645
branches/tags v1.0.2
files peat

Changes

--- a/peat	Tue Feb 23 13:36:05 2016 +0000
+++ b/peat	Tue Feb 23 13:41:50 2016 +0000
@@ -24,6 +24,8 @@
 get_paths = lambda: set()
 verbose = True
 dynamic = None
+last_run = None
+
 
 USAGE = r"""usage: %prog [options] COMMAND
 
@@ -54,10 +56,9 @@
     sys.exit(1)
 
 def check(paths):
-    cutoff = int(time.time() - interval)
     for p in paths:
         try:
-            if os.stat(p).st_mtime >= cutoff:
+            if os.stat(p).st_mtime >= last_run:
                 return True
         except OSError as e:
             # If the file has been deleted since we started watching, don't
@@ -69,6 +70,8 @@
     return False
 
 def run():
+    global last_run
+    last_run = time.time()
     log("running: " + command)
     subprocess.call(command, shell=True)