From: Michael Goldish Subject: [KVM-AUTOTEST PATCH 2/3] KVM test: kvm_subprocess.py: use only unbound methods as close() hooks Date: Tue, 13 Oct 2009 13:48:35 +0200 Message-ID: <1255434516-22142-2-git-send-email-mgoldish@redhat.com> References: <1255434516-22142-1-git-send-email-mgoldish@redhat.com> Cc: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:54809 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759542AbZJMLwO (ORCPT ); Tue, 13 Oct 2009 07:52:14 -0400 In-Reply-To: <1255434516-22142-1-git-send-email-mgoldish@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: close() will pass 'self' as a parameter to the hook functions, i.e. it will call hook(self) instead of just hook(), thus allowing the use of unbound methods rather than bound ones. This allows us to avoid self referencing: if a bound method is used, a reference to it is kept in the class instance, and if the method is bound to the same instance then we have a self-reference that prevents garbage collection. Signed-off-by: Michael Goldish --- client/tests/kvm/kvm_subprocess.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/tests/kvm/kvm_subprocess.py b/client/tests/kvm/kvm_subprocess.py index ede8081..a625315 100755 --- a/client/tests/kvm/kvm_subprocess.py +++ b/client/tests/kvm/kvm_subprocess.py @@ -490,7 +490,7 @@ class kvm_spawn: _wait(self.lock_server_running_filename) # Call all cleanup routines for hook in self.close_hooks: - hook() + hook(self) # Close reader file descriptors for fd in self.reader_fds.values(): try: @@ -583,7 +583,7 @@ class kvm_tail(kvm_spawn): """ # Add a reader and a close hook self._add_reader("tail") - self._add_close_hook(self._join_thread) + self._add_close_hook(kvm_tail._join_thread) # Init the superclass kvm_spawn.__init__(self, command, id, echo, linesep) -- 1.5.4.1