From: "jeremyevans0 (Jeremy Evans)" Date: 2021-08-20T18:34:56+00:00 Subject: [ruby-core:105027] [Ruby master Bug#16889] TracePoint.enable { ... } also activates the TracePoint for other threads, even outside the block Issue #16889 has been updated by jeremyevans0 (Jeremy Evans). Backport set to 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN Tracker changed from Feature to Bug This was discussed at the August 2021 developer meeting, and it was decided that TracePoint#enable with a block will be thread-local by default. However, that change will not take place until after Ruby 3.1. I'm switching this back to bug. ---------------------------------------- Bug #16889: TracePoint.enable { ... } also activates the TracePoint for other threads, even outside the block https://bugs.ruby-lang.org/issues/16889#change-93434 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- ```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: