Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #9 from bosondata/feature/timeout
Browse files Browse the repository at this point in the history
Add timeout support
  • Loading branch information
mrluanma committed Sep 14, 2017
2 parents 6e61bb2 + 63d3663 commit 594287d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bosonnlp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ class BosonNLP(object):
:param bool compress: 是否压缩大于 10K 的请求体,默认为 True。
:param int timeout: HTTP 请求超时时间,默认为 60 秒。
"""

def __init__(self, token, bosonnlp_url=DEFAULT_BOSONNLP_URL, compress=True, session=None):
def __init__(self, token, bosonnlp_url=DEFAULT_BOSONNLP_URL, compress=True, session=None, timeout=60):
self.token = token
self.bosonnlp_url = bosonnlp_url.rstrip('/')
self.compress = compress
self.timeout = timeout

# Enable keep-alive and connection-pooling.
self.session = session or requests.session()
Expand All @@ -71,6 +74,7 @@ def __init__(self, token, bosonnlp_url=DEFAULT_BOSONNLP_URL, compress=True, sess
)

def _api_request(self, method, path, **kwargs):
kwargs.setdefault('timeout', self.timeout)
url = self.bosonnlp_url + path
if method == 'POST':
if 'data' in kwargs:
Expand Down

0 comments on commit 594287d

Please sign in to comment.