Closed tkellogg closed 10 months ago
This could certainly be more clear.
When you set -a 3600
it will output a spacer after 3600 seconds of no activity. So if 1 hour passes with nothing being written to the terminal, a spacer will be output.
Any time a new line gets output to the terminal, the timer is reset.
Does that help? I'm not entirely certain I've answered your question.
Shouldn't there have been a spacer between these records then?
{"ts": "2023-06-19T01:51:34.123682", "title": "WSL 1.3.10 Brings Experimental Memory Reclaim, Updated DXCore and Linux Kernel (phoronix.com)", "href": "https://www.phoronix.com/news/Microsoft-WSL-1.3.10", "comments": "https://news.ycombinator.com/item?id=36387197"}
{"ts": "2023-06-19T06:10:40.154780", "title": "OpenLLM (github.com/bentoml)", "href": "https://github.com/bentoml/OpenLLM", "comments": "https://news.ycombinator.com/item?id=36388219"}
(Also, I'm not sure how often MacOS wakes up to process these ongoing scripts. That could definitely be playing into it as well)
Yes, there certainly should.
The way spacer is implemented uses a background thread to check if enough time has passed to print a spacer. When your Mac is asleep, this thread may not get a chance to run. It's plausible, but tricky to verify with the existing spacer binary (there's no debug logging of any kind).
If sleep is preventing this, and when it wakes up the main thread goes first, reads a line from STDIN, and resets the timer, that could cause the behaviour you're seeing. I'm not sure how I'd go about "fixing" this.
This could be a terrible idea, but can you use the notify crate to be notified when changes happen, rather than sleeping?
The thread that does the printing would still need to sleep. It prints the spacer after a given timeout, so it needs to wake up independently of anything happening to STDIN. I don't think the notify crate would help.
Hey Tim, checking in on this. I don't think there's much help I can offer without more info. Are you able to reproduce this behaviour on the latest version and without your laptop being asleep?
We can close this issue
I'm unsure if this is a bug or a feature, but spacer seems to use CPU wall clock time when determining how long it's waited. I tend to think of this as a bug because it's idea of "time passed" is difficult to articulate or reason about. I honestly can't explain what spacer is doing, aside from randomly inserting breaks (which is still helpful, but it bugs me because i can't explain it).
Sample output from my HN scraper. This is using
tail -f keyword_links.txt | spacer -a 3600
. There's 2 days between these 2 spacers, spacer is set to 1 hour, yet the script seems to have been periodically active throughout the entire weekend while my laptop was asleep.