Skip to content

Commit 59453d8

Browse files
committed
Merge pull request #707 from KeepSafe/close_session_on_err
Close session on exception
2 parents 969f269 + 5c79665 commit 59453d8

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

aiohttp/client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,22 @@ def __init__(self, coro, session):
526526
super().__init__(coro)
527527
self._session = session
528528

529+
@asyncio.coroutine
530+
def __iter__(self):
531+
try:
532+
return (yield from self._coro)
533+
except:
534+
self._session.close()
535+
raise
536+
537+
if PY_35:
538+
def __await__(self):
539+
try:
540+
return (yield from self._coro)
541+
except:
542+
self._session.close()
543+
raise
544+
529545
def __del__(self):
530546
self._session.detach()
531547

0 commit comments

Comments
 (0)