From: Ben Darnell Date: Sun, 25 Mar 2018 15:17:58 +0000 (-0400) Subject: httpclient: Document inability to use sync HTTPClient in async app X-Git-Tag: v5.1.0b1~34^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2326%2Fhead;p=thirdparty%2Ftornado.git httpclient: Document inability to use sync HTTPClient in async app Eliminate a confusing error message when this occurs. Fixes #2325 --- diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 3547631da..9c438d15c 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -54,8 +54,10 @@ from tornado.util import Configurable class HTTPClient(object): """A blocking HTTP client. - This interface is provided for convenience and testing; most applications - that are running an IOLoop will want to use `AsyncHTTPClient` instead. + This interface is provided to make it easier to share code between + synchronous and asynchronous applications. Applications that are + running an `.IOLoop` must use `AsyncHTTPClient` instead. + Typical usage looks like this:: http_client = httpclient.HTTPClient() @@ -70,8 +72,19 @@ class HTTPClient(object): # Other errors are possible, such as IOError. print("Error: " + str(e)) http_client.close() + + .. versionchanged:: 5.0 + + Due to limitations in `asyncio`, it is no longer possible to + use the synchronous ``HTTPClient`` while an `.IOLoop` is running. + Use `AsyncHTTPClient` instead. + """ def __init__(self, async_client_class=None, **kwargs): + # Initialize self._closed at the beginning of the constructor + # so that an exception raised here doesn't lead to confusing + # failures in __del__. + self._closed = True self._io_loop = IOLoop(make_current=False) if async_client_class is None: async_client_class = AsyncHTTPClient