From 7e12b2ed17d37009eff42241206e5e2e869289dd Mon Sep 17 00:00:00 2001 From: wmorgan Date: Wed, 13 Jun 2007 00:39:33 +0000 Subject: [PATCH] yet more better intra-saving exception resilience git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@451 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- bin/sup | 4 ++-- lib/sup.rb | 1 - lib/sup/util.rb | 7 +++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bin/sup b/bin/sup index 3892016..f1d209d 100644 --- a/bin/sup +++ b/bin/sup @@ -254,8 +254,8 @@ rescue Exception => e $exception ||= e ensure unless $opts[:no_threads] - PollManager.stop - SuicideManager.stop + PollManager.stop if PollManager.instantiated? + SuicideManager.stop if PollManager.instantiated? Index.stop_lock_update_thread end diff --git a/lib/sup.rb b/lib/sup.rb index b07ee41..b7c8f02 100644 --- a/lib/sup.rb +++ b/lib/sup.rb @@ -104,7 +104,6 @@ module Redwood end def finish - Redwood::PollManager.stop Redwood::LabelManager.save if Redwood::LabelManager.instantiated? Redwood::ContactManager.save if Redwood::ContactManager.instantiated? Redwood::PersonManager.save if Redwood::PersonManager.instantiated? diff --git a/lib/sup/util.rb b/lib/sup/util.rb index 8f6680e..c2dd4b0 100644 --- a/lib/sup/util.rb +++ b/lib/sup/util.rb @@ -310,6 +310,13 @@ module Singleton def deinstantiate!; @instance = nil; end def method_missing meth, *a, &b raise "no instance defined!" unless defined? @instance + + ## if we've been deinstantiated, just drop all calls. this is + ## useful because threads that might be active during the + ## cleanup process (e.g. polling) would otherwise have to + ## special-case every call to a Singleton object + return nil if @instance.nil? + @instance.send meth, *a, &b end def i_am_the_instance o -- 2.45.2