From e7f5e147cdc32e7660586ce29ca97ccfe14c97f5 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Mon, 30 Mar 2015 10:14:47 -0400 Subject: [PATCH] #23792: also catch interrupt around pipe.write. The previous patch only dealt with KeyboardInterrupt when all of the data had been consumed by the pager. This deals with the interrupt when some data is still pending. --- Lib/pydoc.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index cf9e0f021ce..faaa8595356 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1453,7 +1453,12 @@ def pipepager(text, cmd): proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE) try: with io.TextIOWrapper(proc.stdin, errors='backslashreplace') as pipe: - pipe.write(text) + try: + pipe.write(text) + except KeyboardInterrupt: + # We've hereby abandoned whatever text hasn't been written, + # but the pager is still in control of the terminal. + pass except OSError: pass # Ignore broken pipes caused by quitting the pager program. while True: