[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Properly handle the cancelled failure.
commit 4ec9ff261c020d90ca3c45e9f81c1c9e70ff9936
Author: Arturo Filastò <art@xxxxxxxxx>
Date: Mon Feb 3 18:16:31 2014 +0100
Properly handle the cancelled failure.
---
ooni/errors.py | 11 ++++++++++-
ooni/reporter.py | 2 +-
ooni/tasks.py | 9 +++------
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/ooni/errors.py b/ooni/errors.py
index c167bbe..b845303 100644
--- a/ooni/errors.py
+++ b/ooni/errors.py
@@ -1,3 +1,4 @@
+from twisted.internet.defer import CancelledError
from twisted.internet.defer import TimeoutError as DeferTimeoutError
from twisted.web._newclient import ResponseNeverReceived
@@ -27,7 +28,7 @@ def handleAllFailures(failure):
ConnectionError, NetworkUnreachable, ConnectionLostEarly,
ConnectionNotAllowed, NoAcceptableMethods, ServerFailure,
HostUnreachable, ConnectionRefused, TTLExpired, CommandNotSupported,
- ConnectError, ConnectionLost)
+ ConnectError, ConnectionLost, CancelledError)
return failureToString(failure)
@@ -114,9 +115,14 @@ def failureToString(failure):
elif isinstance(failure.value, AddressNotSupported):
log.err("SOCKS error: AddressNotSupported")
string = 'socks_address_not_supported'
+
elif isinstance(failure.value, SOCKSError):
log.err("Generic SOCKS error")
string = 'socks_error'
+
+ elif isinstance(failure.value, CancelledError):
+ log.err("Task timed out")
+ string = 'task_timed_out'
else:
log.err("Unknown failure type: %s" % type(failure.value))
@@ -204,6 +210,9 @@ class NoPostProcessor(Exception):
class InvalidOption(Exception):
pass
+class TaskTimedOut(Exception):
+ pass
+
def get_error(error_key):
if error_key == 'test-helpers-key-missing':
return CouldNotFindTestHelper
diff --git a/ooni/reporter.py b/ooni/reporter.py
index 545997d..0db13d0 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -36,7 +36,7 @@ from ooni.utils.net import BodyReceiver, StringProducer, userAgents
from ooni.settings import config
-from ooni.tasks import ReportEntry, TaskTimedOut, ReportTracker
+from ooni.tasks import ReportEntry, ReportTracker
class ReporterException(Exception):
pass
diff --git a/ooni/tasks.py b/ooni/tasks.py
index 6e8c507..efca9b0 100644
--- a/ooni/tasks.py
+++ b/ooni/tasks.py
@@ -1,5 +1,6 @@
import time
+from ooni import errors as e
from ooni.settings import config
from twisted.internet import defer, reactor
@@ -59,9 +60,6 @@ class BaseTask(object):
"""
pass
-class TaskTimedOut(Exception):
- pass
-
class TaskWithTimeout(BaseTask):
timeout = 30
# So that we can test the callLater calls
@@ -70,7 +68,7 @@ class TaskWithTimeout(BaseTask):
def _timedOut(self):
"""Internal method for handling timeout failure"""
if self._running:
- self._failed(TaskTimedOut)
+ self._failed(e.TaskTimedOut)
self._running.cancel()
def _cancelTimer(self):
@@ -126,8 +124,7 @@ class Measurement(TaskWithTimeout):
pass
def run(self):
- d = self.netTestMethod()
- return d
+ return self.netTestMethod()
class ReportTracker(object):
def __init__(self, reporters):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits