title: Trouble with Emacs pdb and breakpoints in multi-threaded Python code
body: <p>I am running Emacs 23.2 with <code>python.el</code> and debugging some Python code with <code>pdb</code>. </p>
  
  <p>My code spawns a sibling thread using the <code>threading</code> module and I set a breakpoint at the start of the <code>run()</code> method, but the break is never handled by <code>pdb</code> even though the code definitely runs and works for all intents and purposes. </p>
  
  <p>I was under the impression that I could use <code>pdb</code> to establish breakpoints in <em>any</em> thread, even though full multi-threaded debugging is in fact not supported. </p>
  
  <p>Am I wrong in assuming <code>pdb</code> within an <kbd>M-x</kbd> <code>pdb</code> invocation can break within any thread? If you don't believe me try this minimal example for yourself. </p>
  
  <pre><code>import threading
  
  class ThreadTest(threading.Thread):
      def __init__(self,):
          threading.Thread.__init__(self)
  
      def run(self):
          print "Type M-x pdb, set a breakpoint here then type c &lt;RET&gt;..."
          print "As you can see it does not break!"
  
  if __name__ == '__main__':
      tt = ThreadTest()
  
      tt.start()
  </code></pre>
  
  <p>Thanks to Pierre and the book text he refers to, I tried the option to include <code>pdb.set_trace()</code> as follows: </p>
  
  <pre><code>def run(self):
      import pdb; pdb.set_trace()
      print "Set a breakpoint here then M-x pdb and type c..."
  </code></pre>
  
  <p>But this only breaks and offers <code>pdb</code> controls for <em>step, next, continue</em> etcetera, if it is executed from a console and run directly within the Python interpreter, and crucially <em>not</em> via <kbd>M-x</kbd> <code>pdb</code> - at least with my Emacs and <code>pdb</code> configuration.  </p>
  
  <p>So my original question could do with being rephrased: </p>
  
  <p>Is there a way to invoke a Python program from within Emacs, where that program uses inlined invocation of pdb (thereby supporting breaks in multi-threaded applications), and for there to be a pdb comint control buffer established auto-magically?</p>
  
  <p><em>or</em></p>
  
  <p>If I run my Python application using M-x pdb and it contains an inline invocation of pdb, how best to handle the fact that this results in a pdb-session-within-a-pdb-session with the associated loss of control?</p>