comparison testcases.py @ 134:e84f33a60a5c

Moved process killing logic into platform-specific modules
author Oleg Oshmyan <chortos@inbox.lv>
date Fri, 20 May 2011 14:47:42 +0100
parents 652028850ea4
children ed4035661b85
comparison
equal deleted inserted replaced
133:a9d2aa6810c7 134:e84f33a60a5c
183 if not case.has_called_back: 183 if not case.has_called_back:
184 callback() 184 callback()
185 case.cleanup() 185 case.cleanup()
186 186
187 def cleanup(case): 187 def cleanup(case):
188 #if getattr(case, 'infile', None):
189 # case.infile.close()
190 #if getattr(case, 'outfile', None):
191 # case.outfile.close()
192 if getattr(case, 'process', None) and case.process.returncode is None: 188 if getattr(case, 'process', None) and case.process.returncode is None:
193 # Try KILLing after three unsuccessful TERM attempts in a row 189 kill(case.process)
194 for i in range(3): 190 for name in case.files_to_delete:
195 try: 191 try:
196 terminate(case.process) 192 os.remove(name)
197 except Exception: 193 except OSError:
198 time.sleep(0) 194 # It can't be helped
199 else: 195 pass
200 wait(case.process)
201 break
202 else:
203 # If killing the process is unsuccessful three times in a row,
204 # just silently stop trying
205 for i in range(3):
206 try:
207 kill(case.process)
208 except Exception:
209 time.sleep(0)
210 else:
211 wait(case.process)
212 break
213 if case.files_to_delete:
214 for name in case.files_to_delete:
215 try:
216 os.remove(name)
217 except Exception:
218 # It can't be helped
219 pass
220 196
221 def open_infile(case): 197 def open_infile(case):
222 try: 198 try:
223 case.infile = files.File('/'.join((case.problem.name, case.realinname.replace('$', case.id)))) 199 case.infile = files.File('/'.join((case.problem.name, case.realinname.replace('$', case.id))))
224 except IOError: 200 except IOError: