Revert "add 30 second timeout to all sync ops"

This reverts commit cbc23e5231.
This commit is contained in:
Damien Elmes 2009-11-24 23:35:34 +09:00
parent feaedccc9a
commit 093395b9e0

View file

@ -48,7 +48,6 @@ SYNC_HOST = "anki.ichi2.net"; SYNC_PORT = 80
#SYNC_HOST = "localhost"; SYNC_PORT = 8001 #SYNC_HOST = "localhost"; SYNC_PORT = 8001
KEYS = ("models", "facts", "cards", "media") KEYS = ("models", "facts", "cards", "media")
SOCKET_TIMEOUT=30
########################################################################## ##########################################################################
# Monkey-patch httplib to incrementally send instead of chewing up large # Monkey-patch httplib to incrementally send instead of chewing up large
@ -975,7 +974,6 @@ and cards.id in %s""" % ids2str([c[0] for c in cards])))
size = tmp.tell() size = tmp.tell()
tmp.seek(0) tmp.seek(0)
# open http connection # open http connection
socket.setdefaulttimeout(SOCKET_TIMEOUT)
runHook("fullSyncStarted", size) runHook("fullSyncStarted", size)
headers = { headers = {
'Content-type': 'multipart/form-data; boundary=%s' % 'Content-type': 'multipart/form-data; boundary=%s' %
@ -993,13 +991,11 @@ and cards.id in %s""" % ids2str([c[0] for c in cards])))
os.close(fd) os.close(fd)
os.unlink(name) os.unlink(name)
finally: finally:
socket.setdefaulttimeout(None)
runHook("fullSyncFinished") runHook("fullSyncFinished")
def fullSyncFromServer(self, fields, path): def fullSyncFromServer(self, fields, path):
try: try:
runHook("fullSyncStarted", 0) runHook("fullSyncStarted", 0)
socket.setdefaulttimeout(SOCKET_TIMEOUT)
fields = urllib.urlencode(fields) fields = urllib.urlencode(fields)
src = urllib.urlopen(SYNC_URL + "fulldown", fields) src = urllib.urlopen(SYNC_URL + "fulldown", fields)
(fd, tmpname) = tempfile.mkstemp(dir=os.path.dirname(path), (fd, tmpname) = tempfile.mkstemp(dir=os.path.dirname(path),
@ -1022,7 +1018,6 @@ and cards.id in %s""" % ids2str([c[0] for c in cards])))
os.unlink(path) os.unlink(path)
os.rename(tmpname, path) os.rename(tmpname, path)
finally: finally:
socket.setdefaulttimeout(None)
runHook("fullSyncFinished") runHook("fullSyncFinished")
# Local syncing # Local syncing
@ -1055,11 +1050,14 @@ class HttpSyncServerProxy(SyncServer):
def connect(self, clientVersion=""): def connect(self, clientVersion=""):
"Check auth, protocol & grab deck list." "Check auth, protocol & grab deck list."
if not self.decks: if not self.decks:
import socket
socket.setdefaulttimeout(30)
d = self.runCmd("getDecks", d = self.runCmd("getDecks",
libanki=anki.version, libanki=anki.version,
client=clientVersion, client=clientVersion,
sources=simplejson.dumps(self.sourcesToCheck), sources=simplejson.dumps(self.sourcesToCheck),
pversion=self.protocolVersion) pversion=self.protocolVersion)
socket.setdefaulttimeout(None)
if d['status'] != "OK": if d['status'] != "OK":
raise SyncError(type="authFailed", status=d['status']) raise SyncError(type="authFailed", status=d['status'])
self.decks = d['decks'] self.decks = d['decks']
@ -1108,15 +1106,11 @@ class HttpSyncServerProxy(SyncServer):
data['d'] = None data['d'] = None
data.update(args) data.update(args)
data = urllib.urlencode(data) data = urllib.urlencode(data)
socket.setdefaulttimeout(SOCKET_TIMEOUT)
try:
try: try:
f = urllib2.urlopen(SYNC_URL + action, data) f = urllib2.urlopen(SYNC_URL + action, data)
except (urllib2.URLError, socket.error, socket.timeout, except (urllib2.URLError, socket.error, socket.timeout,
httplib.BadStatusLine): httplib.BadStatusLine):
raise SyncError(type="noResponse") raise SyncError(type="noResponse")
finally:
socket.setdefaulttimeout(None)
ret = f.read() ret = f.read()
if not ret: if not ret:
raise SyncError(type="noResponse") raise SyncError(type="noResponse")