Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions repoze/tm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, application, commit_veto=None):
self.application = application
self.commit_veto = commit_veto
self.transaction = transaction # for testing

def __call__(self, environ, start_response):
transaction = self.transaction
environ[ekey] = True
Expand All @@ -47,8 +47,10 @@ def save_status_and_headers(status, headers, exc_info=None):
ctx.update(status=status, headers=headers)
return start_response(status, headers, exc_info)

iterable = None
try:
for chunk in self.application(environ, save_status_and_headers):
iterable = self.application(environ, save_status_and_headers)
for chunk in iterable:
yield chunk
except Exception:
"""Saving the exception"""
Expand All @@ -58,6 +60,18 @@ def save_status_and_headers(status, headers, exc_info=None):
reraise(type_, value, tb)
finally:
del type_, value, tb
finally:
if hasattr(iterable, 'close'):
try:
iterable.close()
except Exception:
"""Saving the exception"""
try:
type_, value, tb = sys.exc_info()
self.abort()
reraise(type_, value, tb)
finally:
del type_, value, tb

# ZODB 3.8 + has isDoomed
if hasattr(transaction, 'isDoomed') and transaction.isDoomed():
Expand Down