llvm.org GIT mirror llvm / 4f77dbb
[lit] Try to exit more cleanly If all jobs complete successfully, use pool.close() instead of pool.terminate() before waiting for the workers. Zach Turner reported that he was getting "access denied" exceptions from pool.terminate(). Make the workers abort immediately without printing to stderr when they are interrupted. Finally, catch exceptions when attempting to remove our temporary testing directory. On abnormal exit, there can often be open handles that haven't been cleaned up yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301941 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 3 years ago
2 changed file(s) with 25 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
160160 main_with_tmp(builtinParameters)
161161 finally:
162162 if lit_tmp:
163 shutil.rmtree(lit_tmp)
163 try:
164 shutil.rmtree(lit_tmp)
165 except:
166 # FIXME: Re-try after timeout on Windows.
167 pass
164168
165169 def main_with_tmp(builtinParameters):
166170 parser = argparse.ArgumentParser()
1919
2020 import lit.Test
2121
22 def abort_now():
23 """Abort the current process without doing any exception teardown"""
24 sys.stdout.flush()
25 if win32api:
26 win32api.TerminateProcess(win32api.GetCurrentProcess(), 3)
27 else:
28 os.kill(0, 9)
29
2230 ###
2331 # Test Execution Implementation
2432
9098 # This is a sad hack. Unfortunately subprocess goes
9199 # bonkers with ctrl-c and we start forking merrily.
92100 print('\nCtrl-C detected, goodbye.')
93 sys.stdout.flush()
94 os.kill(0,9)
101 abort_now()
95102 self.consumer.update(test_index, test)
96103
97104 class ThreadResultsConsumer(object):
352359 print('\nCtrl-C detected, terminating.')
353360 pool.terminate()
354361 pool.join()
355 os.kill(0,9)
362 abort_now()
356363 return True
357364 win32api.SetConsoleCtrlHandler(console_ctrl_handler, True)
358365
367374 deadline = time.time() + max_time
368375
369376 # Start a process pool. Copy over the data shared between all test runs.
377 # FIXME: Find a way to capture the worker process stderr. If the user
378 # interrupts the workers before we make it into our task callback, they
379 # will each raise a KeyboardInterrupt exception and print to stderr at
380 # the same time.
370381 pool = multiprocessing.Pool(jobs, worker_initializer,
371382 (self.lit_config,
372383 self.parallelism_semaphores))
378389 args=(test_index, test),
379390 callback=self.consume_test_result)
380391 for test_index, test in enumerate(self.tests)]
392 pool.close()
381393
382394 # Wait for all results to come in. The callback that runs in the
383395 # parent process will update the display.
394406 a.get() # Exceptions raised here come from the worker.
395407 if self.hit_max_failures:
396408 break
397 finally:
409 except:
398410 # Stop the workers and wait for any straggling results to come in
399411 # if we exited without waiting on every async result.
400412 pool.terminate()
413 raise
414 finally:
401415 pool.join()
402416
403417 # Mark any tests that weren't run as UNRESOLVED.
462476 execute_test(test, child_lit_config, child_parallelism_semaphores)
463477 return (test_index, test)
464478 except KeyboardInterrupt as e:
465 # This is a sad hack. Unfortunately subprocess goes
466 # bonkers with ctrl-c and we start forking merrily.
467 print('\nCtrl-C detected, goodbye.')
468 traceback.print_exc()
469 sys.stdout.flush()
470 os.kill(0,9)
479 # If a worker process gets an interrupt, abort it immediately.
480 abort_now()
471481 except:
472482 traceback.print_exc()