Hello list,

I have a really weird reference problem with `sys.exc_info`, and, if I'm right, function frames.

The software in question is bjoern, a WSGI web server written in C, which you can find at http://github.com/jonashaag/bjoern.

This WSGI application:

  def app(env, start_response):
      start_response('200 alright', [])
      try:
          a
      except:
          import sys
          sys.exc_info()
      return ['hello']

  import bjoern
  bjoern.run(app, '0.0.0.0', 8080)

works perfect, however, if I make the 7th line an assignment:

  x = sys.exc_info()

I get a segmentation fault after a few requests, the stack trace being:

  #1  frame_clear ()
  #2  collect ()
  #3  _PyObject_GC_Malloc ()
  #4  PyType_GenericAlloc ()
  #5  BaseException_new ()
  #6  type_call ()
  #7  PyObject_Call ()
  #8  PyEval_CallObjectWithKeywords ()
  #9  PyErr_NormalizeException ()
  #10 PyEval_EvalFrameEx ()
  #11 PyEval_EvalCodeEx ()
  #12 function_call ()
  #14 PyObject_CallFunctionObjArgs ()
  #15 wsgi_call_application (request=...) at bjoern/wsgi.c:33

Now that is weird. The only difference between the two functions is that the second one (with the assignment) keeps a reference to the exc_info tuple in the function frame. The `PyThreadState_GET()->exc_{type,value,traceback}` values, however, should be the same in both cases, because the `except:` cleanup resets those to NULL, shouldn't it?

Do you have any tips how to debug this?

Thanks in advance,
Jonas
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to