Code Duplication    Length = 17-21 lines in 2 locations

executor/opensubmitexec/running.py 2 locations

@@ 105-125 (lines=21) @@
102
            logger.debug("Spawning failed: " + str(e))
103
            raise NestedException(instance=self, real_exception=e, output=self.get_output())
104
105
    def expect_output(self, pattern, timeout=-1):
106
        """Wait until the running program performs some given output, or terminates.
107
108
        Args:
109
            pattern:  The pattern the output should be checked for.
110
            timeout (int):  How many seconds should be waited for the output.
111
112
        The pattern argument may be a string, a compiled regular expression,
113
        or a list of any of those types. Strings will be compiled into regular expressions.
114
115
        Returns:
116
            int: The index into the pattern list. If the pattern was not a list, it returns 0 on a successful match.
117
118
        Raises:
119
            TimeoutException: The output did not match within the given time frame.
120
            TerminationException: The program terminated before producing the output.
121
            NestedException: An internal problem occured while waiting for the output.
122
        """
123
        logger.debug("Expecting output '{0}' from '{1}'".format(pattern, self.name))
124
        try:
125
            return self._spawn.expect(pattern, timeout)
126
        except pexpect.exceptions.EOF as e:
127
            logger.debug("Raising termination exception.")
128
            raise TerminationException(instance=self, real_exception=e, output=self.get_output())
@@ 136-152 (lines=17) @@
133
            logger.debug("Expecting output failed: " + str(e))
134
            raise NestedException(instance=self, real_exception=e, output=self.get_output())
135
136
    def sendline(self, text):
137
        """Sends an input line to the running program, including os.linesep.
138
139
        Args:
140
            text (str): The input text to be send. 
141
142
        Raises:
143
            TerminationException: The program terminated before / while / after sending the input.
144
            NestedException: An internal problem occured while waiting for the output.
145
        """
146
        logger.debug("Sending input '{0}' to '{1}'".format(text, self.name))
147
        try:
148
            return self._spawn.sendline(text)
149
        except pexpect.exceptions.EOF as e:
150
            logger.debug("Raising termination exception.")
151
            raise TerminationException(instance=self, real_exception=e, output=self.get_output())
152
        except pexpect.exceptions.TIMEOUT as e:
153
            logger.debug("Raising timeout exception.")
154
            raise TimeoutException(instance=self, real_exception=e, output=self.get_output())
155
        except Exception as e: