Created
October 6, 2011 05:45
-
-
Save wilson/1266609 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_thread = Thread.new do | |
start_working_forever unless worker_thread[:stop] | |
end | |
default = trap(:INT) do | |
timeout = 30 | |
slayer = Thread.new do | |
sleep timeout | |
worker_thread.terminate if worker_thread.alive? | |
end | |
trap(:INT, default) | |
worker_thread[:stop] = true | |
worker_thread.join | |
exit | |
end | |
worker_thread.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment