Skip to content

Commit

Permalink
Fix #497: store ref to warnings module in function's closure
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Sep 9, 2015
1 parent b821d51 commit 1ad88e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def __init__(self, *, connector=None, loop=None, cookies=None,
self._ws_response_class = ws_response_class

if PY_341:
def __del__(self):
def __del__(self, _warnings=warnings):
if not self.closed:
self.close()

warnings.warn("Unclosed client session {!r}".format(self),
ResourceWarning)
_warnings.warn("Unclosed client session {!r}".format(self),
ResourceWarning)
context = {'client_session': self,
'message': 'Unclosed client session'}
if self._source_traceback is not None:
Expand Down
6 changes: 3 additions & 3 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,13 @@ def _post_init(self, loop):
self._source_traceback = traceback.extract_stack(sys._getframe(1))

if PY_341:
def __del__(self):
def __del__(self, _warnings=warnings):
if self._closed:
return
self.close()

warnings.warn("Unclosed response {!r}".format(self),
ResourceWarning)
_warnings.warn("Unclosed response {!r}".format(self),
ResourceWarning)
context = {'client_response': self,
'message': 'Unclosed response'}
if self._source_traceback:
Expand Down
12 changes: 6 additions & 6 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, connector, key, request, transport, protocol, loop):
self._source_traceback = traceback.extract_stack(sys._getframe(1))

if PY_341:
def __del__(self):
def __del__(self, _warnings=warnings):
if self._transport is not None:
if hasattr(self._loop, 'is_closed'):
if self._loop.is_closed():
Expand All @@ -64,8 +64,8 @@ def __del__(self):
self._key, self._request, self._transport, self._protocol,
should_close=True)

warnings.warn("Unclosed connection {!r}".format(self),
ResourceWarning)
_warnings.warn("Unclosed connection {!r}".format(self),
ResourceWarning)
context = {'client_connection': self,
'message': 'Unclosed connection'}
if self._source_traceback is not None:
Expand Down Expand Up @@ -143,16 +143,16 @@ def __init__(self, *, conn_timeout=None, keepalive_timeout=30,
self.cookies = http.cookies.SimpleCookie()

if PY_341:
def __del__(self):
def __del__(self, _warnings=warnings):
if self._closed:
return
if not self._conns:
return

self.close()

warnings.warn("Unclosed connector {!r}".format(self),
ResourceWarning)
_warnings.warn("Unclosed connector {!r}".format(self),
ResourceWarning)
context = {'connector': self,
'message': 'Unclosed connector'}
if self._source_traceback is not None:
Expand Down

0 comments on commit 1ad88e5

Please sign in to comment.