I am writing a program that displays text on a terminal using Unix less (1). Here is the relevant part:
less = subprocess.Popen(['less -F -'], stdin=subprocess.PIPE,
stdout=sys.stdout, shell=True)
try:
less.stdin.write(rfc_text)
less.stdin.flush()
less.stdin = sys.stdin
less.wait()
except IOError:
less.terminate()
return errno.EPIPE
except KeyboardInterrupt:
less.terminate()
return 0
Waiting for it to end, I listen to the KeyboardInterrupt exception. If I catch one, I kill the SIGTERM signal less and exit my program.
Now that this happens, I will return to the invitation of my shell, but the shell no longer repeats what I am writing, and I need to reset (1) so that it works again.
Any ideas on how to make less die without taking my stdin with him to the grave? The full source is available at https://github.com/jforberg/rfc/blob/master/rfc.py
EDIT:. , (1), man (1) C. . , , , , - , .