From 7b56550e0595beca3ff5a63e3287452920e122d1 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Tue, 12 Jul 2016 14:06:50 -0400 Subject: [PATCH] handle: When warning about an unclosed recource, print its source tb --- tests/test_tcp.py | 38 +++++++++++++++++++++++++++++++++++++- uvloop/_testbase.py | 27 ++++++++++++++++++++++----- uvloop/handles/handle.pxd | 3 +++ uvloop/handles/handle.pyx | 18 +++++++++++++++--- 4 files changed, 77 insertions(+), 9 deletions(-) diff --git a/tests/test_tcp.py b/tests/test_tcp.py index 73ff43b..6f2602e 100644 --- a/tests/test_tcp.py +++ b/tests/test_tcp.py @@ -1,5 +1,5 @@ import asyncio -import logging +import gc import socket import unittest.mock import uvloop @@ -584,6 +584,42 @@ class Test_UV_TCP(_TestTCP, tb.UVTestCase): self.loop.run_until_complete(run()) + def test_tcp_handle_unclosed_gc(self): + fut = self.loop.create_future() + + async def server(reader, writer): + writer.transport.abort() + fut.set_result(True) + + async def run(): + addr = srv.sockets[0].getsockname() + await asyncio.open_connection(*addr, loop=self.loop) + await fut + srv.close() + await srv.wait_closed() + + srv = self.loop.run_until_complete(asyncio.start_server( + server, + '127.0.0.1', 0, + family=socket.AF_INET, + loop=self.loop)) + + if self.loop.get_debug(): + rx = r'unclosed resource self + if self._loop._debug: + self._source_traceback = tb_extract_stack(sys_getframe(0)) cdef inline _start_init(self, Loop loop): IF DEBUG: @@ -322,5 +334,5 @@ cdef void __uv_walk_close_all_handles_cb(uv.uv_handle_t* handle, void* arg) with h = handle.data if not h._closed: - warnings_warn("unclosed resource {!r}".format(h), ResourceWarning) + h._warn_unclosed() h._close()