Hi Mark,
On 2016-02-08 06:28, Mark Goodwin wrote:
> 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.
Thanks for looking into this. The error is now gone but I we still get
exit status 1 - if you remove e.g. the -o csv parameter then exit status
is 0. Is that something that could be addressed as well?
(On the cosmetic side, the comment should be before try: to keep pylint
happy.)
Thanks,
--
Marko Myllynen
|