Add timeout parameter to the download function #17

Closed
navels opened this Issue Oct 14, 2012 · 1 comment

Comments

Projects
None yet
2 participants

navels commented Oct 14, 2012

Here's a simple patch (against v2.4) for allowing a timeout value to be set when calling download:

--- /usr/local/lib/python2.7/dist-packages/spynner-2.4-py2.7.egg/spynner/browser.py 2012-10-10 08:14:58.296039078 -0700
+++ browser.py  2012-10-14 13:35:39.877374096 -0700
@@ -1254,7 +1254,7 @@

     #{ Download files

-    def download(self, url, outfd=None):
+    def download(self, url, outfd=None, timeout=None):
         """
         Download a given URL using current cookies.

@@ -1277,6 +1277,7 @@
         cj = _ExtendedNetworkCookieJar()
         cj.setAllCookies(self.cookiesjar.allCookies())
         manager.setCookieJar(cj)
+        itime = time.time()
         reply = manager.get(request)
         if reply.error():
             raise SpynnerError("Download error: %s" % reply.errorString())
@@ -1287,6 +1288,8 @@
             outfd = StringIO()
         self._start_download(reply, outfd)
         while self._download_reply_status is None:
+            if timeout and time.time() - itime > timeout:
+                raise SpynnerTimeout("Timeout reached: %d seconds" % timeout)
            self._events_loop()
         if outfd_set:
             return (reply.downloaded_nbytes if not reply.error() else None)
Owner

kiorky commented Oct 15, 2012

Thx, but can you please make a proper githut pullrequest ?
(fork, apply your patch push back to github and then click on pull request.).

You ll also need to document your feature (say how to use the timeout parameter) at least in readme or better in a test.

@kiorky kiorky closed this in be49016 Mar 7, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment