diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index fc7d7f26..c7e4345a 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -87,7 +87,6 @@ class CurlAsyncHTTPClient(AsyncHTTPClient): for curl in self._curls: curl.close() self._multi.close() - self._closed = True super(CurlAsyncHTTPClient, self).close() def fetch_impl(self, request, callback): diff --git a/tornado/httpclient.py b/tornado/httpclient.py index f93c3c3c..48731c15 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -157,6 +157,7 @@ class AsyncHTTPClient(Configurable): self.defaults = dict(HTTPRequest._DEFAULTS) if defaults is not None: self.defaults.update(defaults) + self._closed = False def close(self): """Destroys this HTTP client, freeing any file descriptors used. @@ -171,6 +172,7 @@ class AsyncHTTPClient(Configurable): ``close()``. """ + self._closed = True if self._async_clients().get(self.io_loop) is self: del self._async_clients()[self.io_loop] @@ -190,6 +192,8 @@ class AsyncHTTPClient(Configurable): Instead, you must check the response's ``error`` attribute or call its `~HTTPResponse.rethrow` method. """ + if self._closed: + raise RuntimeError("fetch() called on closed AsyncHTTPClient") if not isinstance(request, HTTPRequest): request = HTTPRequest(url=request, **kwargs) # We may modify this (to add Host, Accept-Encoding, etc),