Skip to content

Instantly share code, notes, and snippets.

@wilson
Created October 6, 2011 05:45
Show Gist options
  • Save wilson/1266609 to your computer and use it in GitHub Desktop.
Save wilson/1266609 to your computer and use it in GitHub Desktop.
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