title: How to programmatically exit pdb started in eval() or exec() without showing output
body: <p>In my python code I have this line:</p>
  
  <pre><code>try:
      result = eval(command, self.globals, self.locals)
  except SyntaxError:
      exec(command, self.globals, self.locals)
  </code></pre>
  
  <p>The <code>command</code> variable can be any string. Hence the python debugger <code>pdb</code> may be started in <code>eval</code>/<code>exec</code> and still be active when <code>eval</code>/<code>exec</code> is returning. What I want to do is make sure normal program execution is resumed when returning from <code>eval</code>/<code>exec</code>. To just give you an idea, this is approximately the behavior that I want:</p>
  
  <pre><code>try:
      result = eval(command, self.globals, self.locals)
      try: self.globals['pdb'].run('continue')
      except: pass
  except SyntaxError:
      exec(command, self.globals, self.locals)
      try: self.globals['pdb'].run('continue')
      except: pass
  </code></pre>
  
  <p>However the <code>try</code> line is shown in the debugger before it is executed, but I dont want the debugger to show my code at all. Also it doesn't really work... The reason i repeat code is to minimize debugging in my code, else I could just do it after the <code>except</code> block.</p>
  
  <p><strong>So how can I do this?</strong></p>
  
  <p><sub>
  As a sidenote:</p>
  
  <p>If you try to enter the following lines into the IPython or bpython interpreters you'll see that they have the same problem and you are able to step into their code.</p>
  
  <pre><code>import pdb
  pdb.set_trace()
  next
  </code></pre>
  
  <p>However if you do this in the standard cpython interpreter you are returned to the python prompt. The reason for this is obviously because the two former are implemented in python and the last one is not. But my wish is to get the same behavior even when all code is python.
  </sub></p>