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

@ -1461,7 +1461,7 @@ def main(paths, *,
lines=None,
head=False,
cat=False,
sleep=False,
wait=False,
**args):
# keep-open?
if keep_open:
@ -1510,13 +1510,12 @@ def main(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)
time.sleep(wait if wait is not None
else 2 if not Inotify
else 0.01)
except KeyboardInterrupt:
pass
@ -1788,7 +1787,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.")

View File

@ -5126,7 +5126,7 @@ def main(disk, mroots=None, *,
lines=None,
head=False,
cat=False,
sleep=False,
wait=False,
**args):
# keep-open?
if keep_open:
@ -5175,13 +5175,12 @@ def main(disk, mroots=None, *,
# 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)
time.sleep(wait if wait is not None
else 2 if not Inotify
else 0.01)
except KeyboardInterrupt:
pass
@ -5395,7 +5394,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.")

View File

@ -1039,7 +1039,7 @@ def main(path='-', *,
head=False,
cat=False,
coalesce=None,
sleep=None,
wait=None,
keep_open=False,
**args):
# figure out what color should be
@ -1633,14 +1633,14 @@ def main(path='-', *,
# always redraw if we're sleeping, otherwise
# wait for coalesce number of operations
if sleep is not None or count >= (coalesce or 1):
if wait is not None or count >= (coalesce or 1):
event.set()
count = 0
if not keep_open:
break
# don't just flood open calls
time.sleep(sleep or 2)
time.sleep(wait or 2)
except FileNotFoundError as e:
print("error: file not found %r" % path,
@ -1692,7 +1692,7 @@ def main(path='-', *,
with lock:
draw_()
# sleep a minimum amount of time to avoid flickering
time.sleep(sleep or 0.01)
time.sleep(wait or 0.01)
th.Thread(target=background, daemon=True).start()
main_()
@ -1754,10 +1754,8 @@ if __name__ == "__main__":
action='store_true',
help="Only render wear, don't render bd ops. Implies --wear.")
parser.add_argument(
'-w', '--block-cycles',
nargs='?',
'--block-cycles',
type=lambda x: int(x, 0),
const=0,
help="Assumed maximum number of erase cycles when measuring "
"wear. Defaults to the maximum wear on any single block. "
"Implies --wear.")
@ -1919,7 +1917,7 @@ if __name__ == "__main__":
type=lambda x: int(x, 0),
help="Number of operations to coalesce together.")
parser.add_argument(
'-~', '--sleep',
'-w', '--wait',
type=float,
help="Seconds to sleep between draws, coalescing operations "
"in between.")

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)
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.")

View File

@ -152,7 +152,7 @@ def main(path='-', *,
lines=5,
cat=False,
coalesce=None,
sleep=None,
wait=None,
keep_open=False):
lock = th.Lock()
event = th.Event()
@ -175,7 +175,7 @@ def main(path='-', *,
if not keep_open:
break
# don't just flood open calls
time.sleep(sleep or 2)
time.sleep(wait or 2)
except FileNotFoundError as e:
print("error: file not found %r" % path,
@ -200,7 +200,7 @@ def main(path='-', *,
with lock:
ring.draw()
# sleep a minimum amount of time to avoid flickering
time.sleep(sleep or 0.01)
time.sleep(wait or 0.01)
th.Thread(target=background, daemon=True).start()
main_(ring)
@ -240,7 +240,7 @@ if __name__ == "__main__":
type=lambda x: int(x, 0),
help="Number of lines to coalesce together.")
parser.add_argument(
'-~', '--sleep',
'-w', '--wait',
type=float,
help="Seconds to sleep between draws, coalescing lines in "
"between.")

View File

@ -1320,7 +1320,7 @@ def main(csv_paths, *,
lines=None,
head=False,
cat=False,
sleep=False,
wait=False,
**args):
# keep-open?
if keep_open:
@ -1369,13 +1369,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)
time.sleep(wait if wait is not None
else 2 if not Inotify
else 0.01)
except KeyboardInterrupt:
pass
@ -1592,7 +1591,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.")

View File

@ -190,7 +190,7 @@ def main(command, *,
lines=0,
head=False,
cat=False,
sleep=None,
wait=None,
keep_open=False,
keep_open_paths=None,
buffer=False,
@ -285,14 +285,12 @@ def main(command, *,
# try to inotifywait
if keep_open and 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)))
# or sleep
else:
time.sleep(sleep or 2)
time.sleep(wait if wait is not None
else 2 if not (keep_open and Inotify)
else 0.01)
except KeyboardInterrupt:
pass
@ -329,7 +327,7 @@ if __name__ == "__main__":
action='store_true',
help="Pipe directly to stdout.")
parser.add_argument(
'-~', '--sleep',
'-w', '--wait',
type=float,
help="Seconds to sleep between runs. Defaults to 2 seconds.")
parser.add_argument(