]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
httpclient: Document inability to use sync HTTPClient in async app 2326/head
authorBen Darnell <ben@bendarnell.com>
Sun, 25 Mar 2018 15:17:58 +0000 (11:17 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 25 Mar 2018 16:41:02 +0000 (12:41 -0400)
Eliminate a confusing error message when this occurs.

Fixes #2325

tornado/httpclient.py

index 3547631da7aca25b86f2eda4486cd22f1aa4adff..9c438d15c45a789190bc24f07df74973143f6c13 100644 (file)
@@ -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