Skip to content

Commit

Permalink
Refactor: fix wrapper asymmetry (and inaccurate docstring) (#360)
Browse files Browse the repository at this point in the history
* Fix docstring inaccuracy and wrapper asymmetry

* Style fix: expand the multiline conditional expression
  • Loading branch information
mdickinson committed Jul 5, 2021
1 parent 1c8e507 commit 699b924
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion traits_futures/tests/background_call_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_cancellation_vs_started_race_condition(self):
future = submit_call(self.executor, event.set)
listener = CallFutureListener(future=future)

# Ensure the background task is past the cancel_event.is_set() check.
# Ensure the background task is past the cancellation check.
self.assertTrue(event.wait(timeout=TIMEOUT))

# And _now_ cancel before we process any messages.
Expand Down
2 changes: 1 addition & 1 deletion traits_futures/traits_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def submit(self, task):
raise

background_task_wrapper = BackgroundTaskWrapper(
runner, sender, cancel_event
runner, sender, cancel_event.is_set
)
self._worker_pool.submit(background_task_wrapper)

Expand Down
15 changes: 7 additions & 8 deletions traits_futures/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,22 @@ class BackgroundTaskWrapper:
whether cancellation has been requested.
"""

def __init__(self, background_task, sender, cancel_event):
def __init__(self, background_task, sender, cancelled):
self._background_task = background_task
self._sender = sender
self._cancel_event = cancel_event
self._cancelled = cancelled

def __call__(self):
try:
with self._sender:
self.send_control_message(STARTED)
try:
result = (
None
if self._cancel_event.is_set()
else self._background_task(
self.send_custom_message, self._cancel_event.is_set
if self._cancelled():
result = None
else:
result = self._background_task(
self.send_custom_message, self._cancelled
)
)
except BaseException as e:
self.send_control_message(RAISED, marshal_exception(e))
else:
Expand Down

0 comments on commit 699b924

Please sign in to comment.