MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / execute

Method execute

tests/case_script.py:39–57  ·  view source on GitHub ↗

Execute python script in other process. Raises: SurviveException: contains the error message of the script if it terminated before timeout

(self)

Source from the content-addressed store, hash-verified

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
60class TestPythonScript(unittest.TestCase):

Callers 1

assertSurviveMethod · 0.80

Calls 2

joinMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected