From 21cb9f1aa1571970f6db34cccfdc5201fc0cb3d7 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Mon, 15 May 2017 13:45:44 -0400 Subject: [PATCH] Handle null executor cancellations separately from other exceptions --- util/asyncwrapper.py | 7 ++++++- util/saas/useranalytics.py | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/util/asyncwrapper.py b/util/asyncwrapper.py index 4b11c689a..2496a18ec 100644 --- a/util/asyncwrapper.py +++ b/util/asyncwrapper.py @@ -54,10 +54,15 @@ class AsyncExecutorWrapper(object): return f +class NullExecutorCancelled(CancelledError): + def __init__(self): + super(NullExecutorCancelled, self).__init__('Null executor always fails.') + + class NullExecutor(Executor): """ Executor instance which always returns a Future completed with a CancelledError exception. """ def submit(self, _, *args, **kwargs): always_fail = Future() - always_fail.set_exception(CancelledError('Null executor always fails.')) + always_fail.set_exception(NullExecutorCancelled()) return always_fail diff --git a/util/saas/useranalytics.py b/util/saas/useranalytics.py index 82b7bac1c..c7e89c8dd 100644 --- a/util/saas/useranalytics.py +++ b/util/saas/useranalytics.py @@ -5,7 +5,7 @@ from hashlib import sha1 from concurrent.futures import ThreadPoolExecutor from marketorestpython.client import MarketoClient -from util.asyncwrapper import AsyncExecutorWrapper, NullExecutor +from util.asyncwrapper import AsyncExecutorWrapper, NullExecutor, NullExecutorCancelled logger = logging.getLogger(__name__) @@ -18,6 +18,8 @@ def build_error_callback(message_when_exception): def maybe_log_error(response_future): try: response_future.result() + except NullExecutorCancelled: + pass except Exception: logger.exception('User analytics: %s', message_when_exception)