From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Goldish Subject: [KVM-AUTOTEST PATCH 2/4] KVM test: kvm_utils.Thread.join(): allow suppressing the exception Date: Tue, 11 Jan 2011 20:33:20 +0200 Message-ID: <1294770802-1501-2-git-send-email-mgoldish@redhat.com> References: <1294770802-1501-1-git-send-email-mgoldish@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: autotest@test.kernel.org, kvm@vger.kernel.org Return-path: In-Reply-To: <1294770802-1501-1-git-send-email-mgoldish@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autotest-bounces@test.kernel.org Errors-To: autotest-bounces@test.kernel.org List-Id: kvm.vger.kernel.org If suppress_exception is True, the exception raised in the thread will not be re-raised. Signed-off-by: Michael Goldish --- client/tests/kvm/kvm_utils.py | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 8e6cef1..d55594c 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -1188,22 +1188,24 @@ class Thread(threading.Thread): del self._target, self._args, self._kwargs - def join(self, timeout=None): + def join(self, timeout=None, suppress_exception=False): """ Join the thread. If target raised an exception, re-raise it. Otherwise, return the value returned by target. @param timeout: Timeout value to pass to threading.Thread.join(). + @param suppress_exception: If True, don't re-raise the exception. """ threading.Thread.join(self, timeout) try: if self._e: - # Because the exception was raised in another thread, we need - # to explicitly insert the current context into it - s = error.exception_context(self._e[1]) - s = error.join_contexts(error.get_context(), s) - error.set_exception_context(self._e[1], s) - raise self._e[0], self._e[1], self._e[2] + if not suppress_exception: + # Because the exception was raised in another thread, we + # need to explicitly insert the current context into it + s = error.exception_context(self._e[1]) + s = error.join_contexts(error.get_context(), s) + error.set_exception_context(self._e[1], s) + raise self._e[0], self._e[1], self._e[2] else: return self._retval finally: -- 1.7.3.4