From be019e4c4fdea414398ea1e358f978edf57b4913 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Wed, 4 Aug 2010 14:01:26 +0000 Subject: [PATCH] asdfasdr git-svn-id: http://biopieces.googlecode.com/svn/trunk@1033 74ccb610-7750-0410-82ae-013aeee3265d --- code_ruby/Maasha/lib/biopieces.rb | 94 ++++++++++++++++--------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/code_ruby/Maasha/lib/biopieces.rb b/code_ruby/Maasha/lib/biopieces.rb index 6af2ad0..171136b 100644 --- a/code_ruby/Maasha/lib/biopieces.rb +++ b/code_ruby/Maasha/lib/biopieces.rb @@ -80,50 +80,6 @@ class Biopieces @status.set_tmpdir(path) path end - - # Stuff to be done at begin such as setting the exit status - # and signal handlers - def self.do_at_begin - status = Status.new - status.set - exit_status = "OK" - - # Install signal handlers - %w( INT TERM QUIT ).each do |signal| - Signal.trap(signal) do - exit_status = signal - exit - end - end - - exit_status - end - - # Make sure that file streams are closed, tmpdir removed, and - # exit status is written to log file. - def self.do_at_exit(exit_status) - at_exit do - begin - @in.close if @in.respond_to? :close # FIXME: This can never work - @out.close if @out.respond_to? :close # FIXME: Same - rescue Exception => exception - $stderr.puts "Exception caught!" # DEBUG - case exit_status - when 'INT' then exit_status = 'INTERRUPTED' - when 'TERM' then exit_status = 'TERMINATED' - end - exit_status = "DIED" unless exit_status =~ /INT|TERM|QUIT/ - $stderr.puts exit_status - $stderr.puts exception.backtrace - ensure - status = Status.new - FileUtils.remove_entry_secure(status.get_tmpdir) - status.log(exit_status) - status.delete - puts "EXIT STATUS: #{exit_status}" - end - end - end end @@ -628,4 +584,54 @@ class Stream < IO end +# Stuff to be done at begin such as setting the exit status +# and signal handlers +def do_at_begin + status = Status.new + status.set + exit_status = "OK" + + # Install signal handlers + %w( INT TERM QUIT ).each do |signal| + Signal.trap(signal) do + exit_status = signal + exit + end + end + + exit_status +end + +# Make sure that file streams are closed, tmpdir removed, and +# exit status is written to log file. +def do_at_exit(exit_status="OK-martin") + at_exit do + begin + @in.close if @in.respond_to? :close # FIXME: This can never work + @out.close if @out.respond_to? :close # FIXME: Same + rescue Exception => exception + $stderr.puts "Exception caught!" # DEBUG + case exit_status + when 'INT' then exit_status = 'INTERRUPTED' + when 'TERM' then exit_status = 'TERMINATED' + end + exit_status = "DIED" unless exit_status =~ /INT|TERM|QUIT/ + $stderr.puts exit_status + $stderr.puts exception.backtrace + ensure + status = Status.new + FileUtils.remove_entry_secure(status.get_tmpdir) + status.log(exit_status) + status.delete + puts "EXIT STATUS: #{exit_status}" + end + end +end + +exit_status = do_at_begin + +END { + do_at_exit(exit_status) +} + __END__ -- 2.39.5