Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default timeout to requests #27

Merged
merged 2 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions pennylane_ionq/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def __init__(self, **kwargs):

self.HEADERS = {"User-Agent": self.USER_AGENT}

# Ten minute timeout on requests.
self.TIMEOUT_SECONDS = 60 * 10

if self.AUTHENTICATION_TOKEN:
self.set_authorization_header(self.AUTHENTICATION_TOKEN)
else:
Expand Down Expand Up @@ -179,6 +182,8 @@ def request(self, method, **params):

params["headers"] = self.HEADERS

params["timeout"] = self.TIMEOUT_SECONDS

try:
response = method(**params)
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def test_init_default_client(self):
client = api_client.APIClient(authentication_token="")
assert client.BASE_URL.startswith("https://")
assert client.HEADERS["User-Agent"] == client.USER_AGENT
assert client.TIMEOUT_SECONDS == 600

def test_set_authorization_header(self):
"""
Expand Down