Skip to content

Commit 8881005

Browse files
committed
Don't close tempfiles before we're finished
1 parent 33e16f8 commit 8881005

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/click/_termui_impl.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ def get_pager_file(color=None):
381381
if not getattr(stream, "encoding", None):
382382
# wrap in a text stream
383383
stream = MaybeStripAnsi(stream, color=color, encoding=encoding)
384-
with stream:
385-
yield stream
384+
yield stream
386385

387386

388387
@contextlib.contextmanager
@@ -407,12 +406,11 @@ def _pipepager(cmd, color=None):
407406

408407
c = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, env=env)
409408
encoding = get_best_encoding(c.stdin)
410-
try:
411-
yield c.stdin, encoding, color
412-
except (OSError, KeyboardInterrupt):
413-
pass
414-
else:
415-
c.stdin.close()
409+
with c.stdin:
410+
try:
411+
yield c.stdin, encoding, color
412+
except (OSError, KeyboardInterrupt):
413+
pass
416414

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

0 commit comments

Comments
 (0)