Closed alphapapa closed 3 years ago
@dickmao I wouldn't have made that change in plz
and suggested it in request
if that appeared to be the case. For example, I make a synchronous request to https://httpbin.org/delay/5
and watch the Emacs process's CPU usage while it's doing (while (accept-process-output))
, and it remains at 0%, so the Emacs process does not appear to be busy-waiting.
In the PR you linked, I don't see any linked bug report that reports a CPU usage problem, just the title of the commit that implies that such a problem existed.
As well, the Emacs manual recommends this as the way to block on process output. I would hope that, if it spun the CPU busy-waiting, that would be so-noted; and if it's not, we should surely propose a note to be added to the manual.
Testing it again right now, evaling:
(plz 'get "https://httpbin.org/delay/10"
:as 'string :then 'sync :timeout 10)
I then monitor CPU usage in htop, atop, and KSysGuard while waiting for the curl
process to return, and the Emacs process's CPU usage remains at 0%, nor are there spikes of any kind in any process.
If I'm wrong, please show me what I'm missing so I can address the problem in my own projects. Thanks.
I don't trust Eggert. The evolution of processes.texi
is kinda sus.
The only way I would call accept-process-output
is with a nil process and a nonzero timeout, having over the years tried all permutations of arguments including the ever mysterious "just-this-one".
The subtleties of wait_reading_process_output
are such that I don't want to re-litigate this call.
@dickmao So it doesn't peg the CPU when called this way, but you don't trust it to work properly when it's called this way? Well, you could have said that in the first place. Anyway, if it's unreliable when called this way, it would be good to fix it, or at least to report it officially. Do you know of any relevant debbugs reports?
I also see that wait_reading_process_output
has had a few patches in the last year or two, so maybe that problem has been solved.
@dickmao BTW, I learned something else new today when I stumbled upon this section of the Elisp manual: 38.9.4 Accepting Output from Processes. It explains that
(while (accept-process-output process))
can be used to block on subprocess output without having to use a repeating interval in a tight loop. It seems to work fine inplz
, and since it's not looping, it doesn't burn CPU while waiting. I saw thatrequest
uses a loop that checks every 50 ms (and I see that, thankfully, you reduced that from the original 300 ms). So I guess you might want to use this approach as well.