sandbox.py (12882:dd87d7f2f3e5) | sandbox.py (12942:012ed559070a) |
---|---|
1# Copyright (c) 2017 Mark D. Hill and David A. Wood 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 119 unchanged lines hidden (view full) --- 128 self.stderr_thread.start() 129 130 def join_loggers(self): 131 self.stdout_thread.join() 132 self.stderr_thread.join() 133 134 135class SubprocessException(Exception): | 1# Copyright (c) 2017 Mark D. Hill and David A. Wood 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 119 unchanged lines hidden (view full) --- 128 self.stderr_thread.start() 129 130 def join_loggers(self): 131 self.stdout_thread.join() 132 self.stderr_thread.join() 133 134 135class SubprocessException(Exception): |
136 def __init__(self, exception, trace): | 136 def __init__(self, trace): |
137 super(SubprocessException, self).__init__(trace) 138 139class ExceptionProcess(multiprocessing.Process): | 137 super(SubprocessException, self).__init__(trace) 138 139class ExceptionProcess(multiprocessing.Process): |
140 class Status(): | 140 class Status(object): |
141 def __init__(self, exitcode, exception_tuple): 142 self.exitcode = exitcode 143 if exception_tuple is not None: | 141 def __init__(self, exitcode, exception_tuple): 142 self.exitcode = exitcode 143 if exception_tuple is not None: |
144 self.trace = exception_tuple[1] 145 self.exception = exception_tuple[0] | 144 self.trace = exception_tuple[0] |
146 else: | 145 else: |
147 self.exception = None | |
148 self.trace = None 149 150 def __init__(self, *args, **kwargs): 151 multiprocessing.Process.__init__(self, *args, **kwargs) 152 self._pconn, self._cconn = multiprocessing.Pipe() 153 self._exception = None 154 155 def run(self): 156 try: 157 super(ExceptionProcess, self).run() 158 self._cconn.send(None) | 146 self.trace = None 147 148 def __init__(self, *args, **kwargs): 149 multiprocessing.Process.__init__(self, *args, **kwargs) 150 self._pconn, self._cconn = multiprocessing.Pipe() 151 self._exception = None 152 153 def run(self): 154 try: 155 super(ExceptionProcess, self).run() 156 self._cconn.send(None) |
159 except Exception as e: | 157 except Exception: |
160 tb = traceback.format_exc() | 158 tb = traceback.format_exc() |
161 self._cconn.send((e, tb)) | 159 self._cconn.send((tb, )) |
162 raise 163 164 @property 165 def status(self): 166 if self._pconn.poll(): 167 self._exception = self._pconn.recv() 168 169 return self.Status(self.exitcode, self._exception) --- 11 unchanged lines hidden (view full) --- 181 self.io_manager.start_loggers() 182 self.p.start() 183 self.io_manager.close_parent_pipes() 184 self.p.join() 185 self.io_manager.join_loggers() 186 187 status = self.p.status 188 if status.exitcode: | 160 raise 161 162 @property 163 def status(self): 164 if self._pconn.poll(): 165 self._exception = self._pconn.recv() 166 167 return self.Status(self.exitcode, self._exception) --- 11 unchanged lines hidden (view full) --- 179 self.io_manager.start_loggers() 180 self.p.start() 181 self.io_manager.close_parent_pipes() 182 self.p.join() 183 self.io_manager.join_loggers() 184 185 status = self.p.status 186 if status.exitcode: |
189 raise SubprocessException(status.exception, status.trace) | 187 raise SubprocessException(status.trace) |
190 191 def entrypoint(self): 192 self.io_manager.setup() 193 self.params.test.test(self.params) | 188 189 def entrypoint(self): 190 self.io_manager.setup() 191 self.params.test.test(self.params) |