OLD | NEW |
1 """ Parallel execution management """ | 1 """ Parallel execution management """ |
2 | 2 |
3 __author__ = """Copyright Andy Whitcroft 2006""" | 3 __author__ = """Copyright Andy Whitcroft 2006""" |
4 | 4 |
5 import sys, logging, os, pickle, traceback, gc | 5 import sys, logging, os, pickle, traceback, gc, time |
6 from autotest_lib.client.common_lib import error, utils | 6 from autotest_lib.client.common_lib import error, utils |
7 | 7 |
8 def fork_start(tmp, l): | 8 def fork_start(tmp, l): |
9 sys.stdout.flush() | 9 sys.stdout.flush() |
10 sys.stderr.flush() | 10 sys.stderr.flush() |
11 pid = os.fork() | 11 pid = os.fork() |
12 if pid: | 12 if pid: |
13 # Parent | 13 # Parent |
14 return pid | 14 return pid |
15 | 15 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 def fork_waitfor(tmp, pid): | 71 def fork_waitfor(tmp, pid): |
72 (pid, status) = os.waitpid(pid, 0) | 72 (pid, status) = os.waitpid(pid, 0) |
73 | 73 |
74 _check_for_subprocess_exception(tmp, pid) | 74 _check_for_subprocess_exception(tmp, pid) |
75 | 75 |
76 if status: | 76 if status: |
77 raise error.TestError("Test subprocess failed rc=%d" % (status)) | 77 raise error.TestError("Test subprocess failed rc=%d" % (status)) |
78 | 78 |
79 | 79 |
| 80 def fork_waitfor_timed(tmp, pid, timeout): |
| 81 """ |
| 82 Waits for pid until it terminates or timeout expires. |
| 83 If timeout expires, test subprocess is killed. |
| 84 """ |
| 85 timer_expired = True |
| 86 poll_time = 2 |
| 87 time_passed = 0 |
| 88 while time_passed < timeout: |
| 89 time.sleep(poll_time) |
| 90 (child_pid, status) = os.waitpid(pid, os.WNOHANG) |
| 91 if (child_pid, status) == (0, 0): |
| 92 time_passed = time_passed + poll_time |
| 93 else: |
| 94 timer_expired = False |
| 95 break |
| 96 |
| 97 if timer_expired: |
| 98 logging.info('Timer expired (%d sec.), nuking pid %d', timeout, pid) |
| 99 utils.nuke_pid(pid) |
| 100 (child_pid, status) = os.waitpid(pid, 0) |
| 101 raise error.TestError("Test timeout expired, rc=%d" % (status)) |
| 102 else: |
| 103 _check_for_subprocess_exception(tmp, pid) |
| 104 |
| 105 if status: |
| 106 raise error.TestError("Test subprocess failed rc=%d" % (status)) |
| 107 |
| 108 |
80 def fork_nuke_subprocess(tmp, pid): | 109 def fork_nuke_subprocess(tmp, pid): |
81 utils.nuke_pid(pid) | 110 utils.nuke_pid(pid) |
82 _check_for_subprocess_exception(tmp, pid) | 111 _check_for_subprocess_exception(tmp, pid) |
OLD | NEW |