Handle null executor cancellations separately from other exceptions

This commit is contained in:
Jake Moshenko 2017-05-15 13:45:44 -04:00
parent 6023e15274
commit 21cb9f1aa1
2 changed files with 9 additions and 2 deletions

View file

@ -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