From 339fe663321970894c15c7e1e72337eaeea71bfb Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Tue, 15 Mar 2005 13:14:58 +0000 Subject: [PATCH] (Spawn._read): Override the default method to handle EIO properly. (Spawn.kill): New method. --- pcl_expect/spawn.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pcl_expect/spawn.py b/pcl_expect/spawn.py index 6fb2701..a1a4315 100644 --- a/pcl_expect/spawn.py +++ b/pcl_expect/spawn.py @@ -67,6 +67,7 @@ import os import sys import pty +import errno import fcntl import pcl_expect @@ -226,6 +227,20 @@ class Spawn(pcl_expect.Expectable): pcl_expect.debug("sending \"%s\" to fd %d" % (s, self.fileno())) os.write(self.fileno(), s) + def _read(self): + # When reading from a pty, at least under Linux, you get EIO + # when the process dies. Treat this as a normal end-of-file. + try: + return pcl_expect.Expectable._read(self) + except OSError, err: + if err.errno == errno.EIO: + return "", True + raise + + def kill(self, sig): + """Send signal SIG to the child process.""" + os.kill(self.__child_pid, sig) + def close(self): """Close the pty and wait for the child to die. -- GitLab