scripts: Increased default sleep time to 2 seconds

You forget one script, running in the background, hogging a whole
core, and suddenly watch's default 2 second sleep time makes a lot more
sense...

One of the main motivators for watch.py _was_ for shorter sleep times,
short enough to render realtime animations (watch is limited to 0.1
seconds for some reason?), but this doesn't mean it needs to be the
default. This can still be accomplished by explicitly specifying
-s/--sleep, and we probably don't want the default to hog all the CPU.

The use case for fast sleeps has been mostly replaced by -k/--keep-open
anyways.

For tailpipe.py and tracebd.py it's a bit less clear, but we probably
don't need to be spamming open calls 10 times a second.
This commit is contained in:
Christopher Haster
2025-02-12 23:53:53 -06:00
parent eae7665977
commit 2b1738e6d1
4 changed files with 11 additions and 11 deletions
+3 -4
View File
@@ -1445,11 +1445,10 @@ def main(csv_paths, *,
ptime = time.time() ptime = time.time()
inotify.read() inotify.read()
inotify.close() inotify.close()
# sleep for a minimum amount of time, this helps reduce # sleep a minimum amount of time to avoid flickering
# flicker issues
time.sleep(max(0, (sleep or 0.01) - (time.time()-ptime))) time.sleep(max(0, (sleep or 0.01) - (time.time()-ptime)))
else: else:
time.sleep(sleep or 0.1) time.sleep(sleep or 2)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
@@ -1669,7 +1668,7 @@ if __name__ == "__main__":
'-s', '--sleep', '-s', '--sleep',
type=float, type=float,
help="Time in seconds to sleep between redraws when running " help="Time in seconds to sleep between redraws when running "
"with -k. Defaults to 0.01.") "with -k. Defaults to 2 seconds.")
def dictify(ns): def dictify(ns):
if hasattr(ns, 'subplots'): if hasattr(ns, 'subplots'):
+3 -2
View File
@@ -129,6 +129,7 @@ def main(path='-', *,
event.clear() event.clear()
with lock: with lock:
ring.draw() ring.draw()
# sleep a minimum amount of time to avoid flickering
time.sleep(sleep or 0.01) time.sleep(sleep or 0.01)
th.Thread(target=background, daemon=True).start() th.Thread(target=background, daemon=True).start()
@@ -143,7 +144,7 @@ def main(path='-', *,
if not keep_open: if not keep_open:
break break
# don't just flood open calls # don't just flood open calls
time.sleep(sleep or 0.1) time.sleep(sleep or 2)
except FileNotFoundError as e: except FileNotFoundError as e:
print("error: file not found %r" % path, print("error: file not found %r" % path,
file=sys.stderr) file=sys.stderr)
@@ -182,7 +183,7 @@ if __name__ == "__main__":
parser.add_argument( parser.add_argument(
'-s', '--sleep', '-s', '--sleep',
type=float, type=float,
help="Seconds to sleep between reads. Defaults to 0.01.") help="Seconds to sleep between reads.")
parser.add_argument( parser.add_argument(
'-k', '--keep-open', '-k', '--keep-open',
action='store_true', action='store_true',
+2 -1
View File
@@ -1020,6 +1020,7 @@ def main(path='-', *,
draw(ring) draw(ring)
if not cat: if not cat:
ring.draw() ring.draw()
# sleep a minimum amount of time to avoid flickering
time.sleep(sleep or 0.01) time.sleep(sleep or 0.01)
th.Thread(target=background, daemon=True).start() th.Thread(target=background, daemon=True).start()
@@ -1044,7 +1045,7 @@ def main(path='-', *,
if not keep_open: if not keep_open:
break break
# don't just flood open calls # don't just flood open calls
time.sleep(sleep or 0.1) time.sleep(sleep or 2)
except FileNotFoundError as e: except FileNotFoundError as e:
print("error: file not found %r" % path, print("error: file not found %r" % path,
file=sys.stderr) file=sys.stderr)
+3 -4
View File
@@ -247,12 +247,11 @@ def main(command, *,
ptime = time.time() ptime = time.time()
inotify.read() inotify.read()
inotify.close() inotify.close()
# sleep for a minimum amount of time, this helps reduce # sleep a minimum amount of time to avoid flickering
# flicker issues
time.sleep(max(0, (sleep or 0.01) - (time.time()-ptime))) time.sleep(max(0, (sleep or 0.01) - (time.time()-ptime)))
# or sleep # or sleep
else: else:
time.sleep(sleep or 0.1) time.sleep(sleep or 2)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
@@ -291,7 +290,7 @@ if __name__ == "__main__":
parser.add_argument( parser.add_argument(
'-s', '--sleep', '-s', '--sleep',
type=float, type=float,
help="Seconds to sleep between runs. Defaults to 0.1.") help="Seconds to sleep between runs. Defaults to 2 seconds.")
parser.add_argument( parser.add_argument(
'-k', '--keep-open', '-k', '--keep-open',
action='store_true', action='store_true',