Skip to content

Commit

Permalink
Merge pull request #5585 from radarhere/stdout
Browse files Browse the repository at this point in the history
Catch OSError when checking if fp is sys.stdout
  • Loading branch information
hugovk committed Jul 6, 2021
2 parents 340adc5 + f962b18 commit f6c91c3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/PIL/ImageFile.py
Expand Up @@ -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:
Expand Down

0 comments on commit f6c91c3

Please sign in to comment.