Skip to content

Commit

Permalink
clean up sys.exc_info calls to drop circular refs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulnivin committed Mar 18, 2016
1 parent 22a988f commit 9392e7a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
7 changes: 2 additions & 5 deletions gunicorn/_compat.py
Expand Up @@ -107,11 +107,8 @@ def _wrap_error(exc, mapping, key):
new_err = new_err_cls(*exc.args)

# raise a new exception with the original traceback
if hasattr(exc, '__traceback__'):
traceback = exc.__traceback__
else:
traceback = sys.exc_info()[2]
six.reraise(new_err_cls, new_err, traceback)
six.reraise(new_err_cls, new_err,
exc.__traceback__ if hasattr(exc, '__traceback__') else sys.exc_info()[2])

if PY33:
import builtins
Expand Down
13 changes: 8 additions & 5 deletions gunicorn/workers/base.py
Expand Up @@ -134,11 +134,14 @@ def load_wsgi(self):

self.log.exception(e)

exc_type, exc_val, exc_tb = sys.exc_info()
self.reloader.add_extra_file(exc_val.filename)

tb_string = traceback.format_exc(exc_tb)
self.wsgi = util.make_fail_app(tb_string)
try:
exc_type, exc_val, exc_tb = sys.exc_info()
self.reloader.add_extra_file(exc_val.filename)

tb_string = traceback.format_exc(exc_tb)
self.wsgi = util.make_fail_app(tb_string)
finally:
del exc_tb

def init_signals(self):
# reset signaling
Expand Down
3 changes: 1 addition & 2 deletions gunicorn/workers/gthread.py
Expand Up @@ -339,9 +339,8 @@ def handle_request(self, req, conn):
self.log.debug("Closing connection.")
return False
except EnvironmentError:
exc_info = sys.exc_info()
# pass to next try-except level
six.reraise(exc_info[0], exc_info[1], exc_info[2])
six.reraise(*sys.exc_info())
except Exception:
if resp and resp.headers_sent:
# If the requests have already been sent, we should close the
Expand Down
3 changes: 1 addition & 2 deletions gunicorn/workers/sync.py
Expand Up @@ -182,9 +182,8 @@ def handle_request(self, listener, req, client, addr):
if hasattr(respiter, "close"):
respiter.close()
except EnvironmentError:
exc_info = sys.exc_info()
# pass to next try-except level
six.reraise(exc_info[0], exc_info[1], exc_info[2])
six.reraise(*sys.exc_info())
except Exception:
if resp and resp.headers_sent:
# If the requests have already been sent, we should close the
Expand Down

0 comments on commit 9392e7a

Please sign in to comment.