Handle null executor cancellations separately from other exceptions
This commit is contained in:
parent
6023e15274
commit
21cb9f1aa1
2 changed files with 9 additions and 2 deletions
|
@ -54,10 +54,15 @@ class AsyncExecutorWrapper(object):
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
class NullExecutorCancelled(CancelledError):
|
||||||
|
def __init__(self):
|
||||||
|
super(NullExecutorCancelled, self).__init__('Null executor always fails.')
|
||||||
|
|
||||||
|
|
||||||
class NullExecutor(Executor):
|
class NullExecutor(Executor):
|
||||||
""" Executor instance which always returns a Future completed with a
|
""" Executor instance which always returns a Future completed with a
|
||||||
CancelledError exception. """
|
CancelledError exception. """
|
||||||
def submit(self, _, *args, **kwargs):
|
def submit(self, _, *args, **kwargs):
|
||||||
always_fail = Future()
|
always_fail = Future()
|
||||||
always_fail.set_exception(CancelledError('Null executor always fails.'))
|
always_fail.set_exception(NullExecutorCancelled())
|
||||||
return always_fail
|
return always_fail
|
||||||
|
|
|
@ -5,7 +5,7 @@ from hashlib import sha1
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from marketorestpython.client import MarketoClient
|
from marketorestpython.client import MarketoClient
|
||||||
|
|
||||||
from util.asyncwrapper import AsyncExecutorWrapper, NullExecutor
|
from util.asyncwrapper import AsyncExecutorWrapper, NullExecutor, NullExecutorCancelled
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@ def build_error_callback(message_when_exception):
|
||||||
def maybe_log_error(response_future):
|
def maybe_log_error(response_future):
|
||||||
try:
|
try:
|
||||||
response_future.result()
|
response_future.result()
|
||||||
|
except NullExecutorCancelled:
|
||||||
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception('User analytics: %s', message_when_exception)
|
logger.exception('User analytics: %s', message_when_exception)
|
||||||
|
|
||||||
|
|
Reference in a new issue