ALL
Gracefully exiting from console programs in Ruby
Imagine you write a CLI program or a Rake task which loops through some data performing some work on it. You run it and then you remembered something. You’d love to kill the process with ctrl-c, but that will raise an exception somewhere in the loop. What you want is for the iteration to complete and then you want the program to quit.You could handle the Interrupt exception or add some conditions. But how about a cleaner and reusable way?No problem - you can trap signals, which means we can trap the ctrl-c (which is an INT signal). Servers, like unicorn, use signals for graceful restart...
6,744 0 RUBY CONSOLE EXIT COMMAND WINDOW GRACEFUL