diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 8bbebc9be3a..cf9e0f021ce 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1452,11 +1452,18 @@ def pipepager(text, cmd): import subprocess proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE) try: - with proc: - with io.TextIOWrapper(proc.stdin, errors='backslashreplace') as pipe: - pipe.write(text) + with io.TextIOWrapper(proc.stdin, errors='backslashreplace') as pipe: + pipe.write(text) except OSError: pass # Ignore broken pipes caused by quitting the pager program. + while True: + try: + proc.wait() + break + except KeyboardInterrupt: + # Ignore ctl-c like the pager itself does. Otherwise the pager is + # left running and the terminal is in raw mode and unusable. + pass def tempfilepager(text, cmd): """Page through text by invoking a program on a temporary file.""" diff --git a/Misc/NEWS b/Misc/NEWS index c6b5e1ccbff..9852102f903 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -21,6 +21,10 @@ Core and Builtins Library ------- +- Issue #23792: Ignore KeyboardInterrupt when the pydoc pager is active. + This mimics the behavior of the standard unix pagers, and prevents + pipepager from shutting down while the pager itself is still running. + - Issue #23742: ntpath.expandvars() no longer loses unbalanced single quotes. - Issue #21802: The reader in BufferedRWPair now is closed even when closing