开发者

Strange exception with python's cgitb and inspect.py

I have a function that decodes an exception and pushes the info to a file. Following is what I do basically:

exc_info = sys.exc_info
txt = cgitb.text(exc_info)

Using this, I got the following exception trace:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\job_queue\utils\start_workers.py", line 40, in start_worker
  worker_loop(r_jq, worktype, worker_id)
File "C:\Python27\lib\site-packages\job_queue\server\jq_worker.py", line 55, in worker_loop     
  _job_machine(*job)
File "C:\Python27\lib\site-packages\job_queue\server\jq_worker.py", line 34, in _job_machine
  do_verbose_exception()
File "C:\Python27\lib\site-packages\job_queue\server\errors.py", line 23, in do_verbose_exception
  txt = cgitb.text(exc_info)
File "C:\Python27\lib\cgitb.py", line 214, in text
  formatvalue=lambda value: '=' + pydoc.text.repr(value))
File "C:\Python27\lib\inspect.py", line 885, in formatargvalues
  specs.append(strseq(args[i], convert, join))
File "C:\Python27\lib\inspect.py", line 840, in strseq
  return convert(object)
File "C:\Python27\lib\inspect.py", line 882, in convert
  return formatarg(name) + formatvalue(locals[name])
KeyError: 'connection'

I ran the code multiple time开发者_如何学Cs after this exception, but couldn't reproduce it. However, I didn't find any reference in files cgitb.py or inspect.py to a dict with 'connection' key either.

Will anybody know if this is an issue with python's cgitb or inspect files? Any helpful inputs?


You passed a wrong type to text function below is the correct way.

cgitb.text((sys.last_type, sys.last_value, sys.last_traceback))


Im not sure specifically why this exception is happening, but have you read the docs for cgitb module? It seems that since python 2.2 it has supported writing exceptions to a file: http://docs.python.org/library/cgitb.html

Probably something like: cgitb.enable(0, "/my/log/directory") # or 1 if you want to see it in browser

As far as your actual traceback, are you sure 'connection' isnt a name you are using in your own code? 'inspect' module is most likely trying to examine your own code to build the cgi traceback info and getting a bad key somewhere?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜