title: python traceback - performance problems
body: <p>we have a python script that uses a c library to call some low level functions.
  Because of code structure reasons we want to store the stack trace/call stack before each c call.</p>
  
  <p>To do this we use <code>traceback.extract_stack()</code> to extract the call stack of python.
  When an exception occurs later on, we use <code>traceback.format_list(abc)</code> on each element to format and print the stack trace.</p>
  
  <p>The problem is that the function <code>extract_stack</code> is too slow. I slows down our code from 1.7 seconds to 11 seconds.</p>
  
  <p><strong>Is there any function to store the stack trace in order to be able to use/print it later?</strong>
  The stacktrace getter must be very fast. The format function can be slow, this is no problem.</p>
  
  <p>Example:</p>
  
  <pre><code>Stack Trace:
    - LXScript: '_LXS:TOOL:RUNLX'
        File "_LXS:TOOL:RUNLX", line 13, in &lt;module&gt;
        File "lxs", line 1, in &lt;module&gt;
    - UNIFACE ACTIVATE: 'ACTQREC_SVC' 'EXECLXSRP'
    - LXScript: '_DATATRT:ACTQREC:EXECUTE@Main:run'
        File "_LXS:TOOL:RUNLX", line 13, in &lt;module&gt;
        File "lxs", line 1, in &lt;module&gt;
        File "&lt;string&gt;", line 63, in run
        File "&lt;string&gt;", line 97, in __doAll
        File "&lt;string&gt;", line 127, in __do
        File "_DATATRT:ACTQREC:EXECUTE", line 7, in do
    - UNIFACE ACTIVATE: 'ACTQ_CSVC' 'EXECBYREC'
    - LXScript: 'TOOL:ACTQ:SYNLAB_DATA@Main:runOnBeforeExec'
        File "TOOL:ACTQ:SYNLAB_DATA", line 1, in &lt;module&gt;
      ImportError: No module named 'localls'
  </code></pre>