mountstats: Fix spurious I/O errors
diff mbox

Message ID 20141117162339.15387.88477.stgit@manet.1015granger.net
State New, archived
Headers show

Commit Message

Chuck Lever Nov. 17, 2014, 4:23 p.m. UTC
When running mountstats under "watch," occassionally the output
shows "close failed in file object desctructor: sys.excepthook is
missing" and the data display is messed up. This seems to be a
common problem when Python script output is piped to another
program.

Ensure stdout/stderr is completely flushed before mountstats exits,
and add an IOError exception handler to catch these exceptions
gracefully.

Solution suggested by: http://bugs.python.org/issue11380

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 tools/mountstats/mountstats.py |    4 ++++
 1 file changed, 4 insertions(+)


--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Steve Dickson Nov. 17, 2014, 6:32 p.m. UTC | #1
On 11/17/2014 11:23 AM, Chuck Lever wrote:
> When running mountstats under "watch," occassionally the output
> shows "close failed in file object desctructor: sys.excepthook is
> missing" and the data display is messed up. This seems to be a
> common problem when Python script output is piped to another
> program.
> 
> Ensure stdout/stderr is completely flushed before mountstats exits,
> and add an IOError exception handler to catch these exceptions
> gracefully.
> 
> Solution suggested by: http://bugs.python.org/issue11380
> 
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Committed... 

steved.

> ---
>  tools/mountstats/mountstats.py |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/mountstats/mountstats.py b/tools/mountstats/mountstats.py
> index 9a6ec43..e6a456c 100644
> --- a/tools/mountstats/mountstats.py
> +++ b/tools/mountstats/mountstats.py
> @@ -612,8 +612,12 @@ try:
>          nfsstat_command()
>      elif prog == 'ms-iostat':
>          iostat_command()
> +    sys.stdout.close()
> +    sys.stderr.close()
>  except KeyboardInterrupt:
>      print('Caught ^C... exiting')
>      sys.exit(1)
> +except IOError:
> +    pass
>  
>  sys.exit(0)
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/tools/mountstats/mountstats.py b/tools/mountstats/mountstats.py
index 9a6ec43..e6a456c 100644
--- a/tools/mountstats/mountstats.py
+++ b/tools/mountstats/mountstats.py
@@ -612,8 +612,12 @@  try:
         nfsstat_command()
     elif prog == 'ms-iostat':
         iostat_command()
+    sys.stdout.close()
+    sys.stderr.close()
 except KeyboardInterrupt:
     print('Caught ^C... exiting')
     sys.exit(1)
+except IOError:
+    pass
 
 sys.exit(0)