From d4167f97880a35ef5b32433455e804fa1a24e38b Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Wed, 20 Feb 2013 22:03:28 -0500 Subject: [PATCH] Clean up more timeouts when shutting down HTTP clients or finishing tests. --- tornado/curl_httpclient.py | 2 ++ tornado/test/httpclient_test.py | 1 + tornado/testing.py | 5 +++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index 028c80584..f46ea7b87 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -81,6 +81,8 @@ class CurlAsyncHTTPClient(AsyncHTTPClient): def close(self): self._force_timeout_callback.stop() + if self._timeout is not None: + self.io_loop.remove_timeout(self._timeout) for curl in self._curls: curl.close() self._multi.close() diff --git a/tornado/test/httpclient_test.py b/tornado/test/httpclient_test.py index 039720e2d..cfba97929 100644 --- a/tornado/test/httpclient_test.py +++ b/tornado/test/httpclient_test.py @@ -285,6 +285,7 @@ Transfer-Encoding: chunked client.fetch(self.get_url('/user_agent'), callback=self.stop) response = self.wait() self.assertEqual(response.body, b'TestDefaultUserAgent') + client.close() def test_304_with_content_length(self): # According to the spec 304 responses SHOULD NOT include diff --git a/tornado/testing.py b/tornado/testing.py index de6e5b4fb..30fe4e29c 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -223,8 +223,6 @@ class AsyncTestCase(unittest.TestCase): except Exception: self.__failure = sys.exc_info() self.stop() - if self.__timeout is not None: - self.io_loop.remove_timeout(self.__timeout) self.__timeout = self.io_loop.add_timeout(self.io_loop.time() + timeout, timeout_func) while True: self.__running = True @@ -232,6 +230,9 @@ class AsyncTestCase(unittest.TestCase): if (self.__failure is not None or condition is None or condition()): break + if self.__timeout is not None: + self.io_loop.remove_timeout(self.__timeout) + self.__timeout = None assert self.__stopped self.__stopped = False self.__rethrow() -- 2.47.2