Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Fixes
queue. Instead, it will fail fast with a ``QueueError`` exception. This
situation should never happen in normal use; please report it if you ever
witness it.
* The ``ProgressCancelled`` exception used by the background task submitted
* The ``TaskCancelled`` exception used by the background task submitted
via ``submit_progress`` is now public, in case that task needs to catch
the exception.
* The marshal_exception function has been fixed not to rely on the global
Expand Down
4 changes: 2 additions & 2 deletions docs/source/guide/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ from |traits_futures.api|:
"progress" parameter can then be called to send progress reports to the
associated |ProgressFuture| object. If the future has been cancelled, the
next call to ``progress`` in the background task will raise a
|ProgressCancelled| exception.
|TaskCancelled| exception.

For example, your callable might look like this::

Expand Down Expand Up @@ -393,7 +393,7 @@ needed.
.. |submit_iteration| replace:: :func:`~traits_futures.background_iteration.submit_iteration`
.. |result_event| replace:: :attr:`~traits_futures.background_iteration.IterationFuture.result_event`

.. |ProgressCancelled| replace:: :exc:`~traits_futures.background_progress.ProgressCancelled`
.. |TaskCancelled| replace:: :exc:`~traits_futures.base_future.TaskCancelled`
.. |ProgressFuture| replace:: :class:`~traits_futures.background_progress.ProgressFuture`
.. |submit_progress| replace:: :func:`~traits_futures.background_progress.submit_progress`
.. |progress| replace:: :attr:`~traits_futures.background_progress.ProgressFuture.progress`
Expand Down
12 changes: 4 additions & 8 deletions traits_futures/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
- :func:`~.submit_call`
- :func:`~.submit_iteration`
- :func:`~.submit_progress`
- :exc:`~.ProgressCancelled`

Types of futures
----------------

- :class:`~.CallFuture`
- :class:`~.IterationFuture`
- :class:`~.ProgressFuture`
- :exc:`~.TaskCancelled`

Future states
-------------
Expand Down Expand Up @@ -85,12 +85,8 @@
IterationFuture,
submit_iteration,
)
from traits_futures.background_progress import (
ProgressCancelled,
ProgressFuture,
submit_progress,
)
from traits_futures.base_future import BaseFuture, BaseTask
from traits_futures.background_progress import ProgressFuture, submit_progress
from traits_futures.base_future import BaseFuture, BaseTask, TaskCancelled
from traits_futures.ets_event_loop import ETSEventLoop
from traits_futures.executor_states import (
ExecutorState,
Expand Down Expand Up @@ -119,7 +115,7 @@
"CallFuture",
"IterationFuture",
"ProgressFuture",
"ProgressCancelled",
"TaskCancelled",
# Future states
"FutureState",
"CANCELLED",
Expand Down
15 changes: 4 additions & 11 deletions traits_futures/background_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from traits.api import Callable, Dict, Event, HasStrictTraits, Str, Tuple

from traits_futures.base_future import BaseFuture, BaseTask
from traits_futures.base_future import BaseFuture, BaseTask, TaskCancelled
from traits_futures.i_task_specification import ITaskSpecification

# Message types for messages from ProgressTask
Expand All @@ -32,13 +32,6 @@
PROGRESS = "progress"


class ProgressCancelled(Exception):
"""
Exception raised when progress reporting is interrupted by
task cancellation.
"""


class ProgressReporter:
"""
Object used by the target callable to report progress.
Expand All @@ -63,13 +56,13 @@ def report(self, progress_info):

Raises
------
ProgressCancelled
TaskCancelled
If a cancellation request for this task has already been made.
In this case, the exception will be raised before any progress
information is sent.
"""
if self.cancelled():
raise ProgressCancelled("Task was cancelled")
raise TaskCancelled("Task was cancelled")
self.send(PROGRESS, progress_info)


Expand All @@ -94,7 +87,7 @@ def run(self):
**self.kwargs,
progress=progress.report,
)
except ProgressCancelled:
except TaskCancelled:
return None


Expand Down
6 changes: 6 additions & 0 deletions traits_futures/base_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@
}


class TaskCancelled(Exception):
"""
Exception raised within the background task on cancellation.
"""


class _StateTransitionError(Exception):
"""
Exception used to indicate a bad state transition.
Expand Down
4 changes: 2 additions & 2 deletions traits_futures/tests/background_progress_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
EXECUTING,
FAILED,
FutureState,
ProgressCancelled,
ProgressFuture,
submit_progress,
TaskCancelled,
WAITING,
)

Expand Down Expand Up @@ -81,7 +81,7 @@ def syncing_progress(test_ready, raised, progress):
# so that we never get to the following code.
try:
progress("second")
except ProgressCancelled:
except TaskCancelled:
raised.set()
raise

Expand Down
2 changes: 1 addition & 1 deletion traits_futures/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ def test_imports(self):
IterationFuture,
MultiprocessingContext,
MultithreadingContext,
ProgressCancelled,
ProgressFuture,
RUNNING,
STOPPED,
STOPPING,
submit_call,
submit_iteration,
submit_progress,
TaskCancelled,
TraitsExecutor,
WAITING,
)
Expand Down