pcp
[Top] [All Lists]

patch/RFC - pmrep: handling broken pipe and Exception Ignored errors

To: pcp <pcp@xxxxxxxxxxx>
Subject: patch/RFC - pmrep: handling broken pipe and Exception Ignored errors
From: Mark Goodwin <mgoodwin@xxxxxxxxxx>
Date: Mon, 8 Feb 2016 15:28:17 +1100
Delivered-to: pcp@xxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0
A pmrep issue that has been perlexing a few of us where we get unwanted errors 
on exit
when pmrep is piped into e.g. head, as follows :

$ python3 src/pmrep/pmrep.py -a qa/archives/20130706 -o csv -u -S @10:00 
kernel.all.sysfork | head -2
Time,kernel.all.sysfork
2013-07-06 17:43:43,16953707
[Errno 32] Broken pipe
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' 
encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe

'head' exits before our python app and so we get a SIGPIPE. Ignoring SIGPIPE 
seems to
work on python2.x, but in python3 we _also_ get the ugly 'Exception ignored' 
errors.

Turns out it's a known issue in python3 where the destructor is called for 
stdout and/or
stderr whilst there is unflushed i/o, and it complains. For details see the 
discussion at
http://stackoverflow.com/questions/16314321/suppressing-printout-of-exception-ignored-message-in-python-3
and elsewhere.

The attached patch adds exception handlers in pmrep's finalize() to flush and 
close
stdout and stderr before exiting, thus avoiding the errors from the destructor.
This also seems to remove the need to ignore SIGPIPE.

Comments/review welcome, thanks.

Attachment: pmrep_broken_pipe.patch
Description: Text Data

<Prev in Thread] Current Thread [Next in Thread>