From: Joel VanderWerf Date: 2006-02-19T09:18:16+09:00 Subject: Re: Thread#stop And with a little extra work, one can use this to approximate Thread#backtrace as well as Thread#stop (neither of which exist): th = Thread.new do loop do sleep 0.1 puts "alive!" end end sleep 0.3 puts "stopping" stopper = proc {|event, file, line, id, binding, classname| if Thread.current == th puts caller.join("\n from ") Thread.stop end } set_trace_func stopper sleep 1 puts "starting" set_trace_func nil th.wakeup sleep 0.3 alive! alive! stopping thread-stop.rb:6 from thread-stop.rb:6 from thread-stop.rb:4 from thread-stop.rb:3 starting alive! alive! alive! (This is only approximate because the thread isn't stopped until after the interpreter finishes whatever current ruby primitive is evaluating, but it's good enough for my purposes.) -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407