Skip to content

Commit

Permalink
Add timeouts.
Browse files Browse the repository at this point in the history
This also allows the upload to do multiple passes even if it's timing out.
  • Loading branch information
Stephen McMillen committed Sep 16, 2014
1 parent a704ec6 commit b5d962a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions vimeo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def caller(url, *args, **kwargs):
headers['User-Agent'] = self.USER_AGENT
kwargs['headers'] = headers

kwargs['timeout'] = kwargs.get('timeout', (1, 30))

if not url[:4] == "http":
url = self.API_ROOT + url

Expand Down
8 changes: 7 additions & 1 deletion vimeo/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# encoding: utf-8

import os
import requests.exceptions

class UploadVideoMixin(object):
"""Handle uploading a new video to the Vimeo API."""
Expand All @@ -22,7 +23,12 @@ def upload(self, filename):
last_byte = 0
with open(filename) as f:
while last_byte < size:
self._make_pass(target, f, size, last_byte)
try:
self._make_pass(target, f, size, last_byte)
except requests.exceptions.Timeout:
# If there is a timeout here, we are okay with it, since
# we'll check and resume.
pass
last_byte = self._get_progress(target, size)

# Perform the finalization and get the location.
Expand Down

0 comments on commit b5d962a

Please sign in to comment.