title: Use pdb.set_trace() in a script that reads stdin via a pipe
body: <p>I have a python script that reads stdin via a pipe, and I cannot seem to use it with pdb.set_trace().  </p>
  
  <p>my_script.py:</p>
  
  <pre><code>#!/usr/bin/env python
  import sys
  import pdb
  
  def main():
      for line in sys.stdin:
          print "Printing a line: " +line
  
  if __name__=='__main__':
      status = main()
  </code></pre>
  
  <p>Suppose tempfile.csv is some file with two lines,</p>
  
  <pre><code>$ cat tempfile.csv 
  line1
  line2
  </code></pre>
  
  <p>then I can run my script with:
  $ cat tempfile.csv | ./my_script.py, and everything is fine:</p>
  
  <pre><code>$ cat tempfile.csv | ./my_script.py 
  Printing a line:  line1
  
  Printing a line:  line2
  </code></pre>
  
  <p>On the other hand, if I put pdb.set_trace() anywhere then I get an error.  For example, putting pdb.set_trace() below def main(), then I get </p>
  
  <pre><code>$ cat tempfile.csv | ./my_script.py 
  &gt; /home/ilangmore/mobiuss/TM/branches/hadooprotype/my_script.py(7)main()
  -&gt; for line in sys.stdin:
  (Pdb) *** NameError: name 'line1' is not defined
  (Pdb) *** NameError: name 'line2' is not defined
  (Pdb) 
  Traceback (most recent call last):
    File "./my_script.py", line 11, in &lt;module&gt;
      status = main()
    File "./my_script.py", line 7, in main
      for line in sys.stdin:
    File "./my_script.py", line 7, in main
      for line in sys.stdin:
    File "/usr/lib/python2.7/bdb.py", line 48, in trace_dispatch
      return self.dispatch_line(frame)
    File "/usr/lib/python2.7/bdb.py", line 67, in dispatch_line
      if self.quitting: raise BdbQuit
  bdb.BdbQuit
  </code></pre>
  
  <p>Note that my question is probably related to <a href="https://stackoverflow.com/questions/3101777/run-pdb-without-stdin-stdout-using-fifo">this question</a> (i.e. pdb by default reads from stdin), but I need more help.</p>