title: Debugging threaded ruby applications
body: <p>I am developing a ruby application which uses threads. I am having difficulty debugging it. The main problem is that I want to step through a particular thread. I set the breakpoint and run, but nothing happens until I use something like <code>thr sw 2</code>. But then subsequent input is FUBAR'd. I have tried pry, but pry seems no better at dealing with threads.</p>
  
  <p>Solutions? Work-arounds?</p>
  
  <p>EDIT 1:</p>
  
  <p>FYI: <code>Pry version 0.10.1 on Ruby 2.0.0</code> with <code>byebug</code></p>
  
  <p>So here is what I experience with Pry. Try 1:I set the thread-specific breakpoint using <code>break</code></p>
  
  <ol>
  <li>Let program run. </li>
  <li>Breakpoint is triggered.</li>
  <li>Pry correctly shows me the breakpoint and surrounding code.</li>
  <li>Now nothing. <em>I have no prompt</em>. Control-C doesn't work. In fact, I have to kill -9 the process from outside. </li>
  </ol>
  
  <p>Try 2:  Using the "binding.pry" method above. </p>
  
  <ol>
  <li>same</li>
  <li>same</li>
  <li>same! </li>
  <li>I get a Pry prompt! I can yield expressions. </li>
  <li>I try to use "step" or "next" and suddenly I'm in "Pry::history#load" . So now the debugger has jumped to the thread that is processing the input itself.  This is not functional. </li>
  </ol>
  
  <p>Pry output:</p>
  
  <pre><code>[2] pry(#&lt;QDS::Node::Primary&gt;)&gt; step
  
  From: /usr/local/rvm/gems/ruby-2.0.0-p598/gems/pry-0.10.1/lib/pry/history.rb @ line 37 Pry::History#load:
  
      35: def load
      36:   @loader.call do |line|
   =&gt; 37:     @pusher.call(line.chomp)
      38:     @history &lt;&lt; line.chomp
      39:     @original_lines += 1
      40:   end
      41: end
  
  [2] pry(#&lt;Pry::History&gt;)&gt;
  </code></pre>
  
  <ol start="6">
  <li>I try "exit" and now I'm at "pry(main)" without anything else working.</li>
  </ol>
  
  <p>Pry output:</p>
  
  <pre><code>[1] pry(main)&gt; continue
  Error: Cannot find local context. Did you use `binding.pry`?
  </code></pre>