Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ignored exception
#1
i sometimes get this message when i don't want the exception to be ignored:

Output:
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='ANSI_X3.4-1968'> BrokenPipeError: [Errno 32] Broken pipe
something is set in python somewhere to cause this exception to be ignored?  how can i turn it off?  i don't want to catch it myself. i am using python3 as much as i can.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
It makes sense to ignore the exception on stdout (and stderr). But getting "broken pipe" errors on stdout means that you have problems elsewhere (likely not in Python itself).
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#3
the script is outputting too much and i want to get a traceback to find out where, when i pipe it through head.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
(Jun-12-2017, 06:13 AM)Skaperen Wrote: when i pipe it through head.
Could the error be directly tied to the fact that you're using head? Wouldn't that close the pipe after a few lines are read?

Do you also get the error if you use tail?
Reply
#5
encoding='ANSI_X3.4-1968' you still have cool encoding Cool
I have mention before in your Unicode post that your encoding must be wrong.
mint@mint ~/Documents $ python test.py | echo

Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe
mint@mint ~/Documents $ python -c "import sys; print(sys.stdout.encoding)"
UTF-8

mint@mint ~/Documents $ python
Python 3.6.1 (default, May 25 2017, 14:44:39) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'
>>> sys.getfilesystemencoding()
'utf-8'
>>> 
Occasionally, a user's locale is broken and can requires PYTHONIOENCODING=utf-8 to fix the console encoding.
Reply
#6
Try this: https://stackoverflow.com/a/16865106/2817354

https://docs.python.org/3/library/signal.html
Quote:The signal.signal() function allows defining custom handlers to be executed when a signal is received. A small number of default handlers are installed: SIGPIPE is ignored (so write errors on pipes and sockets can be reported as ordinary Python exceptions) and SIGINT is translated into a KeyboardInterrupt exception.

There is also a blog post about it: http://newbebweb.blogspot.de/2012/02/pyt...roken.html
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#7
(Jul-06-2017, 09:20 PM)nilamo Wrote:
(Jun-12-2017, 06:13 AM)Skaperen Wrote: when i pipe it through head.
Could the error be directly tied to the fact that you're using head?  Wouldn't that close the pipe after a few lines are read?

Do you also get the error if you use tail?

bingo! that was the problem!
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  During handling of the above exception, another exception occurred Skaperen 7 26,892 Dec-21-2018, 10:58 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020