scottchiefbaker / dool

Python3 compatible fork of dstat
GNU General Public License v3.0
323 stars 64 forks source link

Add SIGINT/SIGTERM/SIGHUP/SIGBREAK handler to fix missing data issue in --output mode #11

Closed minghungchen closed 1 year ago

minghungchen commented 3 years ago
ISSUE TYPE
DSTAT VERSION
0.9.10
SUMMARY

Add a SIGINT and SIGTERM handler so the data still in the I/O buffer will be written out before exiting the program.

msimonin commented 3 years ago

:+1:

An orthogonal way of doing this is to disable buffering on the file (which might not be efficient for high frequency stats gathering). which is the purpose of https://github.com/scottchiefbaker/dool/pull/12

@minghungchen I'd like to see SIGHUP signal being catched as well, what do you think ?

minghungchen commented 3 years ago

@msimonin Sure. SIGHUP in Linux and SIGBREAK in Windows can be caught now

scottchiefbaker commented 1 year ago

Apologies... Github was not sending me alerts for issues and pull requests on this repo. I did not see this until just now.

Is this still relevant? I'm working through some backlog.

scottchiefbaker commented 1 year ago

I just landed some code that dramatically improves --output and I think addresses this issue. Please check https://github.com/scottchiefbaker/dool/commit/82cf041ba30333da3b73af0d60ea055802ca5779 and let me know. There is a pre-release v1.2.0 available with this code in it.

scottchiefbaker commented 1 year ago

I think I've already fixed most of the stuff related to --output but I want to implement signal handling in the future so this is a good start.

scottchiefbaker commented 1 year ago

@minghungchen is it possible to use signal handling to not output the trailing "^C" on STDOUT if I press CTRL + C to terminate dool?

minghungchen commented 1 year ago

A simple trick is print out a few '\b' and then print something else to overwrite the existing contents, e.g., a few space to overwrite ^c. I did not test in dool but this trick usually works, but might need a flush at the end.

scottchiefbaker commented 1 year ago

@minghungchen oh good call. I just landed eee27c5 which seems to work for covering up "^C"