下面是wsgi web server的片段demo
def start_response(status, response_headers, exc_info=None):
if exc_info:
try:
if headers_sent:
# Re-raise original exception if headers sent
raise exc_info[1].with_traceback(exc_info[2])
finally:
exc_info = None # avoid dangling circular ref
elif headers_set:
raise AssertionError("Headers already set!")
headers_set[:] = [status, response_headers]
# Note: error checking on the headers should happen here,
# *after* the headers are set. That way, if an error
# occurs, start_response can only be re-called with
# exc_info set.
return write
我想问:exc_info = None # avoid dangling circular ref
这里有什么必要这样操作?
这和迷途指针有什么关系吗?
我不怎么写python,但我觉得copilot chat讲得还可以: