Bug #16889
Updated by Eregon (Benoit Daloze) over 5 years ago
```ruby threads = [] inspects = [] trace = TracePoint.new(:line) do |tp| threads << Thread.current inspects << tp.inspect end done = false thread = Thread.new do Thread.pass until done end trace.enable do line_event = true done = true sleep 1 end thread.join # Expected only within enable block (lines 14-16) puts inspects # Expected just 1 p threads.uniq ``` Results in: ``` $ ruby tpbug.rb ruby tpbug.rb #<TracePoint:[email protected]:14> #<TracePoint:[email protected]:15> #<TracePoint:[email protected]:16> #<TracePoint:[email protected]:10> [#<Thread:0x00005571134e3340 run>, #<Thread:[email protected]:9 dead>] ``` But I expected: ``` #<TracePoint:[email protected]:14> #<TracePoint:[email protected]:15> #<TracePoint:[email protected]:16> [#<Thread:0x00005571134e3340 run>] ``` Because the RDoc says: ``` If a block is given, the trace will only be enabled within the scope of the block. ``` For background I'm trying to improve the TracePoint specs in ruby/spec, but they are proving quite unreliable due to this. @ko1 Thoughts?