scripts: Changed -~/--sleep -> -w/--wait to sleep after -k/--keep-open

This changes -w/--wait to sleep _after_ -k/--keep-open, instead of
including the time spent waiting on inotifywait in the sleep time.

1. It's easier, no need to keep track of when we started waiting.

2. It's simpler to reason about.

3. It trivially avoids the multiple wakeup noise that plagued
   watch.py + vim (vim likes to do a bunch of renaming and stuff when
   saving files, including the file 4913 randomly?)

   Avoiding this was previously impossible because -~/--sleep was
   effectively a noop when combined with -k/--keep-open.

---

Also renamed from -~/--sleep -> -w/--wait, which is a bit more intuitive
and avoids possible shell issues with -~.

To make this work, dropped the -w/--block-cycles shortform flag in
dbgtrace.py. It's not like this flag is ever used anyways.

Though at the moment this is ignoring the possible conflict with
-w/--word-bits...
This commit is contained in:
Christopher Haster
2025-11-16 13:51:13 -06:00
parent 7da44f12ae
commit 9bc41099f0
7 changed files with 40 additions and 48 deletions

View File

@ -1916,7 +1916,7 @@ def main(csv_paths, *,
keep_open=False,
head=False,
cat=False,
sleep=False,
wait=False,
**args):
# keep-open?
if keep_open:
@ -1945,13 +1945,12 @@ def main(csv_paths, *,
# try to inotifywait
if Inotify:
ptime = time.time()
inotify.read()
inotify.close()
# 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 2)
# sleep a minimum amount of time to avoid flickering
time.sleep(wait if wait is not None
else 2 if not Inotify
else 0.01)
except KeyboardInterrupt:
pass
@ -2251,7 +2250,7 @@ if __name__ == "__main__":
action='store_true',
help="Pipe directly to stdout.")
parser.add_argument(
'-~', '--sleep',
'-w', '--wait',
type=float,
help="Time in seconds to sleep between redraws when running "
"with -k. Defaults to 2 seconds.")