Execute python script in other process. Raises: SurviveException: contains the error message of the script if it terminated before timeout
(self)
| 37 | self.out, self.err = self.p.communicate() |
| 38 | |
| 39 | def execute(self): |
| 40 | """Execute python script in other process. |
| 41 | |
| 42 | Raises: |
| 43 | SurviveException: contains the error message of the script if it terminated before timeout |
| 44 | """ |
| 45 | self.start() |
| 46 | self.join(self.timeout) |
| 47 | |
| 48 | if self.is_alive(): |
| 49 | self.p.terminate() |
| 50 | self.p.kill() # kill -9 |
| 51 | self.join() |
| 52 | else: |
| 53 | # something unexpected happend here, this script was supposed to survive at least the timeout |
| 54 | if len(self.err) > 0: |
| 55 | output = u"STDOUT: \n\n\n" + self.out.decode('utf-8') |
| 56 | output += u"\n\n\n STDERR: \n\n\n" + self.err.decode('utf-8') |
| 57 | raise AssertionError(output) |
| 58 | |
| 59 | |
| 60 | class TestPythonScript(unittest.TestCase): |
no test coverage detected