Close Requests sessions
authorHarmon <Harmon758@gmail.com>
Tue, 9 Jul 2019 19:50:34 +0000 (14:50 -0500)
committerHarmon <Harmon758@gmail.com>
Tue, 9 Jul 2019 19:50:34 +0000 (14:50 -0500)
Fixes #810
Fixes #1093
Resolves #1237

tweepy/binder.py

index 414bfd95a1bb97563e8fcfcaf6ce7246a20e31c0..487482aa167db5a980829b03bc96ad64ef825b78 100644 (file)
@@ -241,10 +241,13 @@ def bind_api(**config):
 
     def _call(*args, **kwargs):
         method = APIMethod(args, kwargs)
-        if kwargs.get('create'):
-            return method
-        else:
-            return method.execute()
+        try:
+            if kwargs.get('create'):
+                return method
+            else:
+                return method.execute()
+        finally:
+            method.session.close()
 
     # Set pagination mode
     if 'cursor' in APIMethod.allowed_param: