parallel.py revision 0e6192aa2853fb4dd98cbad705471b3fb135e70e
1""" Parallel execution management """ 2 3__author__ = """Copyright Andy Whitcroft 2006""" 4 5import sys, os, pickle 6from autotest_lib.client.common_lib import error 7 8def fork_start(tmp, l): 9 sys.stdout.flush() 10 sys.stderr.flush() 11 pid = os.fork() 12 if pid: 13 # Parent 14 return pid 15 16 try: 17 try: 18 l() 19 20 except error.AutotestError: 21 raise 22 23 except: 24 raise error.UnhandledError("test failed and threw:\n") 25 26 except Exception, detail: 27 ename = tmp + "/debug/error-%d" % (os.getpid()) 28 pickle.dump(detail, open(ename, "w")) 29 30 sys.stdout.flush() 31 sys.stderr.flush() 32 os._exit(1) 33 34 sys.stdout.flush() 35 sys.stderr.flush() 36 os._exit(0) 37 38 39def fork_waitfor(tmp, pid): 40 (pid, status) = os.waitpid(pid, 0) 41 42 ename = tmp + "/debug/error-%d" % pid 43 if (os.path.exists(ename)): 44 raise pickle.load(file(ename, 'r')) 45 46 if (status != 0): 47 raise error.TestError("test failed rc=%d" % (status)) 48