这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion grequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
from functools import partial
import traceback

try:
import gevent
from gevent import monkey as curious_george
Expand All @@ -22,7 +23,6 @@

from requests import Session


__all__ = (
'map', 'imap',
'get', 'options', 'head', 'post', 'put', 'patch', 'delete', 'request'
Expand All @@ -47,6 +47,9 @@ def __init__(self, method, url, **kwargs):
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:
Expand All @@ -73,6 +76,11 @@ def send(self, **kwargs):
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


Expand Down