From: Adam Beguelin Date: 2005-10-14T02:16:15+09:00 Subject: Thread leak? ------=_NextPart_000_007D_01C5CFDF.1E7025D0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit The following code seems to leak threads. Is there a better way to handle timeouts so they don't leak threads? I tested it on both windows and linux and the results are the same. If you set t to nil in the rescue the result is the same. Adam require 'timeout' include ObjectSpace begin execLine = "sleep 100" while true do t = Thread.new { begin e = IO.popen(execLine) e.readlines ensure e.close if (e && !e.closed?) end } begin timeout(1) { t.join } rescue TimeoutError => e puts "timeout: "+e.to_s t.kill end c = 0 ObjectSpace.garbage_collect ObjectSpace.each_object{|t| c += 1 if t.class == Thread} puts "num threads #{c}" break if c > 20 end end ------=_NextPart_000_007D_01C5CFDF.1E7025D0--