From: eregontp@... Date: 2021-07-04T10:43:53+00:00 Subject: [ruby-core:104504] [Ruby master Feature#16889] TracePoint.enable { ... } also activates the TracePoint for other threads, even outside the block Issue #16889 has been updated by Eregon (Benoit Daloze). > The reason for this is that there are many tests and specs where this is not desired behavior, because they don't want to test tracing of the block itself, but tracing during the block. Right, I guess the expectation is that `.enable { ... }` also reports events from calls inside that block. Maybe `.enable { ... }` should enable events only on that Thread (or better, Fiber) then? That feels intuitive and I think is good enough for compatibility, what do you think? ---------------------------------------- Feature #16889: TracePoint.enable { ... } also activates the TracePoint for other threads, even outside the block https://bugs.ruby-lang.org/issues/16889#change-92774 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) ---------------------------------------- ```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 # # # # [#, #] ``` But I expected: ``` # # # [#] ``` 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? -- https://bugs.ruby-lang.org/ Unsubscribe: