title: subprocess child traceback
body: <p>I want to access the traceback of a python programm running in a subprocess.</p>
  
  <p><a href="https://docs.python.org/2/library/subprocess.html#exceptions" rel="nofollow">The documentation</a> says:</p>
  
  <blockquote>
    <p>Exceptions raised in the child process, before the new program has started to execute, will be re-raised in the parent. Additionally, the exception object will have one extra attribute called child_traceback, which is a string containing traceback information from the child’s point of view.</p>
  </blockquote>
  
  <p>Contents of <code>my_sub_program.py</code>:</p>
  
  <pre><code>raise Exception("I am raised!")
  </code></pre>
  
  <p>Contents of <code>my_main_program.py</code>:</p>
  
  <pre><code>import sys
  import subprocess
  try:
      subprocess.check_output([sys.executable, "my_sub_program.py"])
  except Exception as e:
      print e.child_traceback
  </code></pre>
  
  <p>If I run <code>my_main_program.py</code>, I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "my_main_program.py", line 6, in &lt;module&gt;
      print e.child_traceback
  AttributeError: 'CalledProcessError' object has no attribute 'child_traceback'
  </code></pre>
  
  <p>How can I access the traceback of the subprocess without modifying the subprocess program code? This means, I want to avoid adding a large <code>try/except</code> clause around my whole sub-program code, but rather handle error logging from my main program.</p>
  
  <p><strong>Edit:</strong> <code>sys.executable</code> should be replaceable with an interpreter differing from the one running the main program.</p>