Revision: 6443
Author: kim
Date: 2009-02-26 00:01:56 +0000 (Thu, 26 Feb 2009)
Log Message:
-----------
Add configuration directive retry_on_fail (default True, which gives the original
behaviour).
If False, pywikipedia will not retry connecting if the first attempt fails.
(while testing, if the wiki to be tested was broken, the test script would hang forever)
Modified Paths:
--------------
trunk/pywikipedia/config.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/config.py
===================================================================
--- trunk/pywikipedia/config.py 2009-02-25 23:37:32 UTC (rev 6442)
+++ trunk/pywikipedia/config.py 2009-02-26 00:01:56 UTC (rev 6443)
@@ -401,6 +401,10 @@
# Use the experimental disk cache to prevent huge memory usage
use_diskcache = False
+# Retry loading a page on failure (back off 1 minute, 2 minutes, 4 minutes
+# up to 30 minutes)
+retry_on_fail = True
+
# End of configuration section
# ============================
# System-level and User-level changes.
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2009-02-25 23:37:32 UTC (rev 6442)
+++ trunk/pywikipedia/wikipedia.py 2009-02-26 00:01:56 UTC (rev 6443)
@@ -759,7 +759,7 @@
elif text.find(self.site().mediawiki_message('badaccess')) != -1
or \
text.find("<div class=\"permissions-errors\">")
!= -1:
raise NoPage(self.site(), self.aslink(forceInterwiki = True))
- else:
+ elif config.retry_on_fail:
if text.find( "<title>Wikimedia Error</title>")
> -1:
output( u"Wikimedia has technical problems; will retry in %i
minutes." % retry_idle_time)
else:
@@ -771,6 +771,9 @@
retry_idle_time *= 2
if retry_idle_time > 30:
retry_idle_time = 30
+ else:
+ output( u"Failed to access wiki")
+ sys.exit(1)
# Check for restrictions
m = re.search('var wgRestrictionEdit = \\["(\w+)"\\]', text)
if m:
@@ -4635,7 +4638,7 @@
return response, data
- def getUrl(self, path, retry = True, sysop = False, data = None,
+ def getUrl(self, path, retry = None, sysop = False, data = None,
compress = True, no_hostname = False, cookie_only=False):
"""
Low-level routine to get a URL from the wiki.
@@ -4651,6 +4654,10 @@
Returns the HTML text of the page converted to unicode.
"""
+
+ if retry==None:
+ retry=config.retry_on_fail
+
if False: #self.persistent_http and not data:
self.conn.putrequest('GET', path)
self.conn.putheader('User-agent', useragent)
Show replies by date