diff --git a/AUTHORS.rst b/AUTHORS.rst index b93507b..dc2e98c 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -1,12 +1,36 @@ -GRequests is written and maintained by Kenneth Reitz and +GRequests is authored by Kenneth Reitz, maintained by Spencer Young and various contributors: -Development Lead -```````````````` +Development Leads +````````````````` +- Spencer Phillip Young - Kenneth Reitz Patches and Suggestions ``````````````````````` -- Kracekumar -- Spencer Young + +Adam Tauber +Akshat Mahajan +Alexander Simeonov +Antonio A +Chris Drackett +Eugene Eeo +Frost Ming +Ian Cordasco +Joe Gordon +Luke Hutscal +Marc Abramowitz +Mathieu Lecarme +Michael Newman +Mircea Ulinic +Nate Lawson +Nathan Hoad +Roman Haritonov +Ryan T. Dean +Spencer Phillip Young +Spencer Young +Yuri Prezument +koobs +kracekumar +崔庆才丨静觅 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..9d5d250 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include LICENSE +include README.rst diff --git a/README.rst b/README.rst index 3ea3e86..e586c5f 100644 --- a/README.rst +++ b/README.rst @@ -3,6 +3,9 @@ GRequests allows you to use Requests with Gevent to make asynchronous HTTP Requests easily. + +|version| |pyversions| + **Note**: You should probably use `requests-threads `_ or `requests-futures `_ instead. @@ -45,7 +48,7 @@ .. code-block:: python >>> def exception_handler(request, exception): - ... print "Request failed" + ... print("Request failed") >>> reqs = [ ... grequests.get('http://httpbin.org/delay/1', timeout=0.001), @@ -65,3 +68,10 @@ $ pip install grequests ✨🍰✨ + + +.. |version| image:: https://img.shields.io/pypi/v/grequests.svg?colorB=blue + :target: https://pypi.org/project/grequests/ + +.. |pyversions| image:: https://img.shields.io/pypi/pyversions/grequests.svg? + :target: https://pypi.org/project/grequests/ diff --git a/grequests.py b/grequests.py index 582cffb..f4ec5c7 100755 --- a/grequests.py +++ b/grequests.py @@ -10,6 +10,7 @@ """ from functools import partial import traceback + try: import gevent from gevent import monkey as curious_george @@ -21,7 +22,6 @@ curious_george.patch_all(thread=False, select=False) from requests import Session - __all__ = ( 'map', 'imap', @@ -47,6 +47,9 @@ self.session = kwargs.pop('session', None) if self.session is None: self.session = Session() + self._close = True + else: + self._close = False # don't close adapters after each request if the user provided the session callback = kwargs.pop('callback', None) if callback: @@ -73,6 +76,11 @@ except Exception as e: self.exception = e self.traceback = traceback.format_exc() + finally: + if self._close: + # if we provided the session object, make sure we're cleaning up + # because there's no sense in keeping it open at this point if it wont be reused + self.session.close() return self @@ -123,6 +131,8 @@ ret.append(request.response) elif exception_handler and hasattr(request, 'exception'): ret.append(exception_handler(request, request.exception)) + elif exception_handler and not hasattr(request, 'exception'): + ret.append(exception_handler(request, None)) else: ret.append(None) diff --git a/setup.py b/setup.py index defc7cf..9122abd 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ setup( name='grequests', - version='0.4.0', + version='0.6.0', url='https://github.com/kennethreitz/grequests', license='BSD', author='Kenneth Reitz',