]> git.cworth.org Git - sup/blobdiff - lib/sup/suicide.rb
bugfix: clear cached lambda hook locals after hook call
[sup] / lib / sup / suicide.rb
index 6c3141e7cea1fbdaa875fdad471d9a66e4e887fc..98b43462eea250aa6969221d0a8456b9697bd54a 100644 (file)
@@ -1,8 +1,5 @@
-require 'fileutils'
 module Redwood
 
-class SuicideException < StandardError; end
-
 class SuicideManager
   include Singleton
 
@@ -10,20 +7,30 @@ class SuicideManager
 
   def initialize fn
     @fn = fn
+    @die = false
+    @thread = nil
     self.class.i_am_the_instance self
+    FileUtils.rm_f @fn
   end
 
-  def start_thread
-    Redwood::reporting_thread do
+  bool_reader :die
+
+  def start
+    @thread = Redwood::reporting_thread("suicide watch") do
       while true
         sleep DELAY
         if File.exists? @fn
-          FileUtils.rm_rf @fn
-          raise SuicideException
+          FileUtils.rm_f @fn
+          @die = true
         end
       end
     end
   end
+
+  def stop
+    @thread.kill if @thread
+    @thread = nil
+  end
 end
 
 end