Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f375b0a

Browse files
committed
Merge: #23792: Ignore KeyboardInterrupt when the pydoc pager is active.
2 parents 1b74d63 + 1058cda commit f375b0a

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Lib/pydoc.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,11 +1450,18 @@ def pipepager(text, cmd):
14501450
import subprocess
14511451
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE)
14521452
try:
1453-
with proc:
1454-
with io.TextIOWrapper(proc.stdin, errors='backslashreplace') as pipe:
1455-
pipe.write(text)
1453+
with io.TextIOWrapper(proc.stdin, errors='backslashreplace') as pipe:
1454+
pipe.write(text)
14561455
except OSError:
14571456
pass # Ignore broken pipes caused by quitting the pager program.
1457+
while True:
1458+
try:
1459+
proc.wait()
1460+
break
1461+
except KeyboardInterrupt:
1462+
# Ignore ctl-c like the pager itself does. Otherwise the pager is
1463+
# left running and the terminal is in raw mode and unusable.
1464+
pass
14581465

14591466
def tempfilepager(text, cmd):
14601467
"""Page through text by invoking a program on a temporary file."""

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ Core and Builtins
3030
Library
3131
-------
3232

33+
- Issue #23792: Ignore KeyboardInterrupt when the pydoc pager is active.
34+
This mimics the behavior of the standard unix pagers, and prevents
35+
pipepager from shutting down while the pager itself is still running.
36+
3337
- Issue #23775: pprint() of OrderedDict now outputs the same representation
3438
as repr().
3539

0 commit comments

Comments
 (0)