Module EDActionExecuteSystemCommand
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 __authors__ = [ "Marie-Francoise Incardona", "Olof Svensson", "Jerome Kieffer" ]
30 __contact__ = "svensson@esrf.fr"
31 __license__ = "LGPLv3+"
32 __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
33
34 """
35 This class is used for executing and controlling external applications
36 such as scripts.
37 """
38
39
40 import os, subprocess, signal
41
42 from EDAction import EDAction
43 from EDVerbose import EDVerbose
44
45
46
48 """
49 This class executes a process using the Python os.sytem command.
50 It is a temporary solution for the "==>[ERROR]: OSError: [Errno 10] No child processes"
51 problem with ALActionProcess (Python bug in subprocess, see bug #61).
52 """
53
54
56 """
57 Initializes the class: the argument _strCommand should be
58 the complete command line, i.e. path to executable + command line arguments
59 """
60 EDAction.__init__(self)
61 self.__strCommand = _strCommand
62 self.__strExecutionStatus = None
63 self.__subprocess = None
64 self.__iPID = None
65
66
68 """
69 Executes the command line using the standard Python os.system command.
70 The result of the os.system command is converted into an str.
71 """
72 EDVerbose.DEBUG("*** EDActionExecuteSystemCommand.process")
73 self.__subprocess = subprocess.Popen (self.__strCommand, shell=True)
74 self.__iPID = self.__subprocess.pid
75 executionStatus = self.__subprocess.wait()
76 if (executionStatus is None):
77
78 self.__strExecutionStatus = str()
79 else:
80 self.__strExecutionStatus = str(executionStatus)
81
82
84 """
85 Returns the string containing the execution status.
86 """
87 return self.__strExecutionStatus
88
89
90 - def abort(self, _edObject=None):
91 """
92 This method can be used to abort the process, for example when
93 the execution time has exceeded the maximum allowed execution time.
94 """
95 EDVerbose.DEBUG("*** EDActionExecuteSystemCommand.abort")
96 os.kill(self.__iPID, signal.SIGKILL)
97 self.m_bIsAbort = True
98