]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add a close method to AsyncHTTPClient.
authorBen Darnell <bdarnell@beaker.local>
Thu, 18 Mar 2010 20:27:49 +0000 (13:27 -0700)
committerBen Darnell <bdarnell@beaker.local>
Thu, 18 Mar 2010 20:27:49 +0000 (13:27 -0700)
tornado/httpclient.py

index e65ed40ecb1cc32751ebbb4d7ad1dec1ab8d8a3f..a87384542dfcf77868f1b39742f59504199503f6 100644 (file)
@@ -124,6 +124,17 @@ class AsyncHTTPClient(object):
             cls._ASYNC_CLIENTS[io_loop] = instance
             return instance
 
+    def close(self):
+        """Destroys this http client, freeing any file descriptors used.
+        Not needed in normal use, but may be helpful in unittests that
+        create and destroy http clients.  No other methods may be called
+        on the AsyncHTTPClient after close().
+        """
+        del AsyncHTTPClient._ASYNC_CLIENTS[self.io_loop]
+        for curl in self._curls:
+            curl.close()
+        self._multi.close()
+
     def fetch(self, request, callback, **kwargs):
         """Executes an HTTPRequest, calling callback with an HTTPResponse.