From 2b1738e6d196028347156579af3e052a81d276c1 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 12 Feb 2025 23:53:53 -0600 Subject: [PATCH] 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. --- scripts/plot.py | 7 +++---- scripts/tailpipe.py | 5 +++-- scripts/tracebd.py | 3 ++- scripts/watch.py | 7 +++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/plot.py b/scripts/plot.py index 0bae380b..32fc62fa 100755 --- a/scripts/plot.py +++ b/scripts/plot.py @@ -1445,11 +1445,10 @@ def main(csv_paths, *, ptime = time.time() inotify.read() inotify.close() - # sleep for a minimum amount of time, this helps reduce - # flicker issues + # sleep a minimum amount of time to avoid flickering time.sleep(max(0, (sleep or 0.01) - (time.time()-ptime))) else: - time.sleep(sleep or 0.1) + time.sleep(sleep or 2) except KeyboardInterrupt: pass @@ -1669,7 +1668,7 @@ if __name__ == "__main__": '-s', '--sleep', type=float, 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): if hasattr(ns, 'subplots'): diff --git a/scripts/tailpipe.py b/scripts/tailpipe.py index e2a85379..ee3a1efa 100755 --- a/scripts/tailpipe.py +++ b/scripts/tailpipe.py @@ -129,6 +129,7 @@ def main(path='-', *, event.clear() with lock: ring.draw() + # sleep a minimum amount of time to avoid flickering time.sleep(sleep or 0.01) th.Thread(target=background, daemon=True).start() @@ -143,7 +144,7 @@ def main(path='-', *, if not keep_open: break # don't just flood open calls - time.sleep(sleep or 0.1) + time.sleep(sleep or 2) except FileNotFoundError as e: print("error: file not found %r" % path, file=sys.stderr) @@ -182,7 +183,7 @@ if __name__ == "__main__": parser.add_argument( '-s', '--sleep', type=float, - help="Seconds to sleep between reads. Defaults to 0.01.") + help="Seconds to sleep between reads.") parser.add_argument( '-k', '--keep-open', action='store_true', diff --git a/scripts/tracebd.py b/scripts/tracebd.py index 21a5ab27..039d7b2b 100755 --- a/scripts/tracebd.py +++ b/scripts/tracebd.py @@ -1020,6 +1020,7 @@ def main(path='-', *, draw(ring) if not cat: ring.draw() + # sleep a minimum amount of time to avoid flickering time.sleep(sleep or 0.01) th.Thread(target=background, daemon=True).start() @@ -1044,7 +1045,7 @@ def main(path='-', *, if not keep_open: break # don't just flood open calls - time.sleep(sleep or 0.1) + time.sleep(sleep or 2) except FileNotFoundError as e: print("error: file not found %r" % path, file=sys.stderr) diff --git a/scripts/watch.py b/scripts/watch.py index 90a77cc7..4d84591a 100755 --- a/scripts/watch.py +++ b/scripts/watch.py @@ -247,12 +247,11 @@ def main(command, *, ptime = time.time() inotify.read() inotify.close() - # sleep for a minimum amount of time, this helps reduce - # flicker issues + # sleep a minimum amount of time to avoid flickering time.sleep(max(0, (sleep or 0.01) - (time.time()-ptime))) # or sleep else: - time.sleep(sleep or 0.1) + time.sleep(sleep or 2) except KeyboardInterrupt: pass @@ -291,7 +290,7 @@ if __name__ == "__main__": parser.add_argument( '-s', '--sleep', 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( '-k', '--keep-open', action='store_true',