| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
GaudiTest.GaudiFilterExecutable Class Reference
Inheritance diagram for GaudiTest.GaudiFilterExecutable:
[legend]
Collaboration diagram for GaudiTest.GaudiFilterExecutable:
[legend]

## Public Member Functions
def | __init__ (self, input, timeout=-1)

## Public Attributes
| stack_trace_file

## Private Member Functions
def | __UseSeparateProcessGroupForChild (self)
def | _HandleChild (self)
| Needs to replace the ones from RedirectedExecutable and TimeoutExecutable. More...
def | __Monitor (self)

## Private Attributes
| __input
| __timeout
| __monitor_pid
| __monitor_thread
| This is the interesting part: dump the stack trace to a file. More...

## Detailed Description

Definition at line 987 of file GaudiTest.py.

## Constructor & Destructor Documentation

def GaudiTest.GaudiFilterExecutable.__init__ | ( |  | self,
|  |  | input,
|  |  | timeout = `-1`
| ) |  |

    Create a new 'Filter'.

    'input' -- The string containing the input to provide to the
    child process.

    'timeout' -- As for 'TimeoutExecutable.__init__'.

Definition at line 988 of file GaudiTest.py.

988 def __init__(self, input, timeout=-1):
989 """Create a new 'Filter'.
990
991 'input' -- The string containing the input to provide to the
992 child process.
993
994 'timeout' -- As for 'TimeoutExecutable.__init__'."""
995
996 super(GaudiFilterExecutable, self).__init__(input, timeout)
997 self.__input = input
998 self.__timeout = timeout
999 self.stack_trace_file = None
1000 # Temporary file to pass the stack trace from one process to the other
1001 # The file must be closed and reopened when needed to avoid conflicts
1002 # between the processes
1003 tmpf = tempfile.mkstemp()
1004 os.close(tmpf[0])
1005 self.stack_trace_file = tmpf[1] # remember only the name
1006
GaudiTest.GaudiFilterExecutable.__init__
def __init__(self, input, timeout=-1)
Definition: GaudiTest.py:988
GaudiTest.GaudiFilterExecutable.__input
__input
Definition: GaudiTest.py:997
GaudiTest.GaudiFilterExecutable.__timeout
__timeout
Definition: GaudiTest.py:998
GaudiTest.GaudiFilterExecutable.stack_trace_file
stack_trace_file
Definition: GaudiTest.py:999

## Member Function Documentation

def GaudiTest.GaudiFilterExecutable.__Monitor | ( |  | self | ) |
| private

    Code copied from FilterExecutable.
    Kill the child if the timeout expires.

    This function is run in the monitoring thread.

Definition at line 1128 of file GaudiTest.py.

1128 def __Monitor(self):
1129 """Code copied from FilterExecutable.
1130 Kill the child if the timeout expires.
1131
1132 This function is run in the monitoring thread."""
1133
1134 # The timeout may be expressed as a floating-point value
1135 # on UNIX, but it must be an integer number of
1136 # milliseconds when passed to WaitForSingleObject.
1137 timeout = int(self.__timeout * 1000)
1138 # Wait for the child process to terminate or for the
1139 # timer to expire.
1140 result = win32event.WaitForSingleObject(self._GetChildPID(),
1141 timeout)
1142 # If the timeout occurred, kill the child process.
1143 if result == win32con.WAIT_TIMEOUT:
1144 self.Kill()
1145
GaudiTest.GaudiFilterExecutable.__timeout
__timeout
Definition: GaudiTest.py:998
GaudiTest.GaudiFilterExecutable.__Monitor
def __Monitor(self)
Definition: GaudiTest.py:1128

def GaudiTest.GaudiFilterExecutable.__UseSeparateProcessGroupForChild | ( |  | self | ) |
| private

    Copied from TimeoutExecutable to allow the re-implementation of
       _HandleChild.

Definition at line 1007 of file GaudiTest.py.

1007 def __UseSeparateProcessGroupForChild(self):
1008 """Copied from TimeoutExecutable to allow the re-implementation of
1009 _HandleChild.
1010 """
1011 if sys.platform == "win32":
1012 # In Windows 2000 (or later), we should use "jobs" by
1013 # analogy with UNIX process groups. However, that
1014 # functionality is not (yet) provided by the Python Win32
1015 # extensions.
1016 return 0
1017
1018 return self.__timeout >= 0 or self.__timeout == -2
GaudiTest.GaudiFilterExecutable.__timeout
__timeout
Definition: GaudiTest.py:998
GaudiTest.GaudiFilterExecutable.__UseSeparateProcessGroupForChild
def __UseSeparateProcessGroupForChild(self)
Definition: GaudiTest.py:1007

def GaudiTest.GaudiFilterExecutable._HandleChild | ( |  | self | ) |
| private

Needs to replace the ones from RedirectedExecutable and TimeoutExecutable.

    Code copied from both FilterExecutable and TimeoutExecutable.

Definition at line 1022 of file GaudiTest.py.

1022 def _HandleChild(self):
1023 """Code copied from both FilterExecutable and TimeoutExecutable.
1024 """
1025 # Close the pipe ends that we do not need.
1026 if self._stdin_pipe:
1027 self._ClosePipeEnd(self._stdin_pipe[0])
1028 if self._stdout_pipe:
1029 self._ClosePipeEnd(self._stdout_pipe[1])
1030 if self._stderr_pipe:
1031 self._ClosePipeEnd(self._stderr_pipe[1])
1032
1033 # The pipes created by 'RedirectedExecutable' must be closed
1034 # before the monitor process (created by 'TimeoutExecutable')
1035 # is created. Otherwise, if the child process dies, 'select'
1036 # in the parent will not return if the monitor process may
1037 # still have one of the file descriptors open.
1038
1039 super(qm.executable.TimeoutExecutable, self)._HandleChild()
1040
1041 if self.__UseSeparateProcessGroupForChild():
1042 # Put the child into its own process group. This step is
1043 # performed in both the parent and the child; therefore both
1044 # processes can safely assume that the creation of the process
1045 # group has taken place.
1046 child_pid = self._GetChildPID()
1047 try:
1048 os.setpgid(child_pid, child_pid)
1049 except:
1050 # The call to setpgid may fail if the child has exited,
1051 # or has already called 'exec'. In that case, we are
1052 # guaranteed that the child has already put itself in the
1053 # desired process group.
1054 pass
1055 # Create the monitoring process.
1056 #
1057 # If the monitoring process is in parent's process group and
1058 # kills the child after waitpid has returned in the parent, we
1059 # may end up trying to kill a process group other than the one
1060 # that we intend to kill. Therefore, we put the monitoring
1061 # process in the same process group as the child; that ensures
1062 # that the process group will persist until the monitoring
1063 # process kills it.
1064 self.__monitor_pid = os.fork()
1065 if self.__monitor_pid != 0:
1066 # Make sure that the monitoring process is placed into the
1067 # child's process group before the parent process calls
1068 # 'waitpid'. In this way, we are guaranteed that the process
1069 # group as the child
1070 os.setpgid(self.__monitor_pid, child_pid)
1071 else:
1072 # Put the monitoring process into the child's process
1073 # group. We know the process group still exists at
1074 # this point because either (a) we are in the process
1075 # group, or (b) the parent has not yet called waitpid.
1076 os.setpgid(0, child_pid)
1077
1078 # Close all open file descriptors. They are not needed
1079 # in the monitor process. Furthermore, when the parent
1080 # closes the write end of the stdin pipe to the child,
1081 # we do not want the pipe to remain open; leaving the
1082 # pipe open in the monitor process might cause the child
1083 # to block waiting for additional input.
1084 try:
1085 max_fds = os.sysconf("SC_OPEN_MAX")
1086 except:
1087 max_fds = 256
1088 for fd in xrange(max_fds):
1089 try:
1090 os.close(fd)
1091 except:
1092 pass
1093 try:
1094 if self.__timeout >= 0:
1095 # Give the child time to run.
1096 time.sleep(self.__timeout)
1097 #######################################################
1098 # This is the interesting part: dump the stack trace to a file
1099 if sys.platform == "linux2": # we should be have /proc and gdb
1100 cmd = ["gdb",
1101 os.path.join(
1102 "/proc", str(child_pid), "exe"),
1103 str(child_pid),
1104 "-batch", "-n", "-x",
1105 "'%s'" % os.path.join(os.path.dirname(__file__), "stack-trace.gdb")]
1106 # FIXME: I wanted to use subprocess.Popen, but it doesn't want to work
1107 # in this context.
1108 o = os.popen(" ".join(cmd)).read()
1109 open(self.stack_trace_file, "w").write(o)
1110 #######################################################
1111
1112 # Kill all processes in the child process group.
1113 os.kill(0, signal.SIGKILL)
1114 else:
1115 # This call to select will never terminate.
1116 select.select([], [], [])
1117 finally:
1118 # Exit. This code is in a finally clause so that
1119 # we are guaranteed to get here no matter what.
1120 os._exit(0)
1121 elif self.__timeout >= 0 and sys.platform == "win32":
1122 # Create a monitoring thread.
1123 self.__monitor_thread = Thread(target=self.__Monitor)
1124 self.__monitor_thread.start()
1125
GaudiTest.GaudiFilterExecutable._HandleChild
def _HandleChild(self)
Needs to replace the ones from RedirectedExecutable and TimeoutExecutable.
Definition: GaudiTest.py:1022
hivetimeline.read
def read(f, regex='.*', skipevents=0)
Definition: hivetimeline.py:22
GaudiTest.GaudiFilterExecutable.__timeout
__timeout
Definition: GaudiTest.py:998
GaudiTest.GaudiFilterExecutable.__monitor_thread
__monitor_thread
This is the interesting part: dump the stack trace to a file.
Definition: GaudiTest.py:1123
GaudiTest.GaudiFilterExecutable.__Monitor
def __Monitor(self)
Definition: GaudiTest.py:1128
GaudiTest.GaudiFilterExecutable.__UseSeparateProcessGroupForChild
def __UseSeparateProcessGroupForChild(self)
Definition: GaudiTest.py:1007
GaudiTest.GaudiFilterExecutable.__monitor_pid
__monitor_pid
Definition: GaudiTest.py:1064
GaudiPython.GaudiAlgs.write
write
Definition: GaudiAlgs.py:1259
GaudiTest.GaudiFilterExecutable.stack_trace_file
stack_trace_file
Definition: GaudiTest.py:999

## Member Data Documentation

GaudiTest.GaudiFilterExecutable.__input
| private

Definition at line 997 of file GaudiTest.py.

GaudiTest.GaudiFilterExecutable.__monitor_pid
| private

Definition at line 1064 of file GaudiTest.py.

GaudiTest.GaudiFilterExecutable.__monitor_thread
| private

This is the interesting part: dump the stack trace to a file.

Definition at line 1123 of file GaudiTest.py.

GaudiTest.GaudiFilterExecutable.__timeout
| private

Definition at line 998 of file GaudiTest.py.

GaudiTest.GaudiFilterExecutable.stack_trace_file

Definition at line 999 of file GaudiTest.py.

The documentation for this class was generated from the following file:

- GaudiPolicy/qmtest_classes/GaudiTest.py