Skip to content

Commit

Permalink
Don't close tempfiles before we're finished
Browse files Browse the repository at this point in the history
  • Loading branch information
craigds committed Dec 23, 2020
1 parent 3c0a22e commit 19f5ac3
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/click/_termui_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ def get_pager_file(color=None):
if not getattr(stream, "encoding", None):
# wrap in a text stream
stream = MaybeStripAnsi(stream, color=color, encoding=encoding)
with stream:
yield stream
yield stream


@contextlib.contextmanager
Expand All @@ -420,12 +419,11 @@ def _pipepager(cmd, color=None):

c = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, env=env)
encoding = get_best_encoding(c.stdin)
try:
yield c.stdin, encoding, color
except (OSError, KeyboardInterrupt):
pass
else:
c.stdin.close()
with c.stdin:
try:
yield c.stdin, encoding, color
except (OSError, KeyboardInterrupt):
pass

# Less doesn't respect ^C, but catches it for its own UI purposes (aborting
# search or other commands inside less).
Expand Down

0 comments on commit 19f5ac3

Please sign in to comment.