From: martinahansen Date: Fri, 6 Aug 2010 09:33:05 +0000 (+0000) Subject: ruby exit status battle part #12312423 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=d260d9f8cfb51301ca3f6bb99b951cee2fe3e3f6;p=biopieces.git ruby exit status battle part #12312423 git-svn-id: http://biopieces.googlecode.com/svn/trunk@1038 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/Maasha/lib/biopieces.rb b/code_ruby/Maasha/lib/biopieces.rb index f2776f2..222e53b 100644 --- a/code_ruby/Maasha/lib/biopieces.rb +++ b/code_ruby/Maasha/lib/biopieces.rb @@ -602,36 +602,31 @@ def do_at_begin exit_status end +exit_status = do_at_begin + # 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 "DEBUG EXIT STATUS: #{exit_status}" # DEBUG - end +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 "DEBUG EXIT STATUS: #{exit_status}" # DEBUG end end -exit_status = do_at_begin - -END { - do_at_exit(exit_status) -} __END__