Say I have this code:
for i in range(200):
print("\n" * 200)
and I run it like this:
$ python oops.py | less
then quit less before scrolling down, Python throws an exception:
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'>
OSError: [Errno 22] Invalid argument
How do I handle this cleanly? Ideally I want to behave like cat
does and silently stop, however the exception doesn't appear to have any information in it other than "invalid argument".