If I started a thread with the following code, how can I capture / detect an exit call from the thread itself so that I can do some cleanup before it finishes?
thr = Thread.new { sleep } thr.status # => "sleep" thr.exit thr.status # => false
I thought it might be something like the following, but I'm not sure.
thr = Thread.new { begin sleep rescue StandardError => ex puts ex.message rescue SystemExit, Interrupt puts 'quit' ensure puts 'quit' end } thr.status
source share