Catch OSError when checking if fp is sys.stdout

This commit is contained in:
Andrew Murray 2021-07-06 11:00:03 +10:00
parent 9b4fff85b3
commit c712d68df2

View File

@ -493,7 +493,11 @@ def _save(im, fp, tile, bufsize=0):
# But, it would need at least the image size in most cases. RawEncode is
# a tricky case.
bufsize = max(MAXBLOCK, bufsize, im.size[0] * 4) # see RawEncode.c
if fp == sys.stdout or (hasattr(sys.stdout, "buffer") and fp == sys.stdout.buffer):
try:
stdout = fp == sys.stdout or fp == sys.stdout.buffer
except (OSError, AttributeError):
stdout = False
if stdout:
fp.flush()
return
try: