title: How can the line numbers in my stack traces be wrong?
body: <p>I have a python (version 2.7.6) program that had been running for a day or two as of last night when it reported some errors. However, the stack traces were blatantly wrong. Pretend my code is like this:</p>
  
  <pre><code>def do_A():
      do_some_stuff()
      do_B()
  
  def do_B():
      do_some_IO_that_could_fail()
  
  def do_C():
      if len('abc'):
          do_D()
  
  def do_D():
      do_other_stuff()
  
  if __name__ == '__main__':
      do_A()
  </code></pre>
  
  <p>The task that can fail did fail, <em>but my stack trace was like this</em>:</p>
  
  <pre><code>Traceback (most recent call last):
    File "myfile.py", line 16, in &lt;module&gt;
      do_A()
    File "myfile.py", line 9, in do_A
      if len('abc'):
    File "myfile.py", line 13, in do_B
      do_other_stuff()
    CustomFailureException: "The thing that can fail? It failed."
  </code></pre>
  
  <p>In my stack trace, the "in ..." parts are reasonable in that they describe a path that can actually get to the part of my code that has the <code>CustomFailureException</code>. The line numbers and the code it shows are consistent (i.e it says line 9 and has the code that's on line 9), but it's the wrong line.</p>
  
  <p><strong>Does anyone have any clue how this could happen to my stack trace?</strong></p>
  
  <p>Note: This particular task runs every night, and has been doing so for a while. It normally finishes successfully, but it has failed before and given a normal stack trace. Last night, it consistently failed and consistently gave the same incorrect stack trace.</p>