3 ms·
Gracefully exiting from console programs in Ruby
- tomku 15y agoThis looks like a cool technique, but what happens if the process gets stuck in a loop somewhere (maybe in third-party code, or waiting on I/O) where you can't put calls to the check method in? Maybe it'd be a good idea to check to see if the flag is already set in the handler, and immediately exit in that case. That way, hitting ctrl-C once would cause a graceful shutdown, while hitting it twice (which is a pretty typical reaction if the first doesn't cause a quick exit) would force-quit in emergencies.
- marcinbunsch 15y agoGreat point - something like this? https://gist.github.com/2038115 https://gist.github.com/2038115