damageboy / yaap

.NET version of python's excellent tqdm (https://github.com/tqdm/tqdm)
MIT License
30 stars 4 forks source link

Progress loses sync after ^Z + fg #1

Open roji opened 6 years ago

damageboy commented 6 years ago

That's a very good point.

I will unfortunately have to close the issue as it is pretty much impossible for me to do anything about this, since the suspension and resumption of the process aren't really something a Unix process can respond to or detect.

I will however add this as a caveat in the Yaap FAQ.

If you feel I'm wrong about this (the ability to handle this from a Unix process) then feel free to correct me.. For now, I'm closing the issue.

roji commented 6 years ago

This doesn't seem true - it's possible to set up a signal handler for SIGCONT, as these docs mention:

You can send a SIGCONT signal to a process to make it continue. This signal is special—it always makes the process continue if it is stopped, before the signal is delivered. The default behavior is to do nothing else. You cannot block this signal. You can set a handler, but SIGCONT always makes the process continue regardless.

Most programs have no reason to handle SIGCONT; they simply resume execution without realizing they were ever stopped. You can use a handler for SIGCONT to make a program do something special when it is stopped and continued—for example, to reprint a prompt when it is suspended while waiting for input.

Note the specific example of reprinting a prompt.

There may be a subtle difference here between suspending and resuming, and being in the foreground or background. In other words, receiving SIGCONT by itself doesn't necessarily mean that the process is in the foreground (we can do ^Z and then bg). I'm guessing there's some way for a process to be aware about foreground/background.

damageboy commented 6 years ago

OK, Thanks for the information.

So I'm not sure what would be considered "proper" behavior here.

As far as you are concerned, simply repainting all of the Yaap progress bars that are "in-progress" from scratch (e.g. in their current state) is a good outcome of SIGCONT?

Visually speaking, this would mean that there are half-finished progress bars, possibly hanging around the top of the terminal window, while there are live progress bars being repainted and updated at the bottom.

It would still be impossible for Yaap to detect "what happenned" during the time it was out...

So, in short, would simply repainting the progress bar be enough?