Subclassing Executable
John Schmitt
jschmitt at kealia.com
Mon Apr 7 22:12:53 UTC 2003
More questions from a wannabe-clueful user.
I tried to subclass InputExecutable to do some pretty low-tech stuff. I
wanted to spawn a process that would kill a test that ran too long.
Here's the kind of thing I'm doing, with stuff snipped to keep this
message reasonably short:
class TimedExecutable(InputExecutable):
def Spawn(self, arguments=[], environment = None, dir = None,
path = None, exception_pipe = None):
self.__child = os.fork()
if self.__child == 0:
# see Executable.Spawn in /usr/local/lib/qm/qm/executable.py
else:
# my additions
if self.timeout:
killerpid = os.fork()
if killerpid != 0:
basetime = os.times()[4]
while 1:
time.sleep( 1 )
totaltime = os.times()[4] - basetime;
if totaltime > self.timeout:
os.kill( self.__child, signal.SIGKILL )
break
os._exit( 1 )
return self.__child
I didn't understand why select.select wouldn't return. So I forced it
(by giving it a timeout too) but QMTest still wouldn't return. What I
mean by that is, if I run the test from the GUI, QMTest reports that the
test has not yet completed even though top and ps showed that the test
did run and was killed by somebody, as intended.
One more thing I wasn't clear on: there was a problem with referencing
__dir, for which I've pasted the traceback below. I could work around
this, though.
ERROR An exception occurred.
Annotation Value
qmtest.exception exceptions.AttributeError: TimedExecutable instance has
no attribute '_Executable__dir' qmtest.traceback
File "/lib/qm/qm/test/target.py", line 208, in RunTest
File "/lib/qm/qm/test/database.py", line 281, in Run
File "/lib/qm/qm/test/database.py", line 188, in _Execute
File "", line 0, in ?
File "/home/build/testbot/testbot.py", line 511, in Run
self.RunProgram(self.program, [ self.program ] + self.arguments,
context, result)
File "/home/build/testbot/testbot.py", line 447, in RunProgram
exit_status = e.Run( args, environment )
File "/home/build/testbot/testbot.py", line 407, in Run
raise exc_info[0], exc_info[1]
Can anyone point to what I'm missing to get this done? Thanks for the
input.
-- John
More information about the qmtest
mailing list