Skip to content

Commit 9d1aa13

Browse files
author
Joel Collins
committed
Expanded thread documentation
1 parent 4325806 commit 9d1aa13

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

docs/basic_usage/action_tasks.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,24 @@ All Actions will return a serialized representation of the task, when your POST
1717

1818
Most users will not need to create instances of this class. Instead, they will be created automatically when a function is started by an API Action view.
1919

20-
.. autoclass:: labthings.tasks.TaskThread
20+
.. autoclass:: labthings.actions.ActionThread
2121
:members:
2222

23+
Accessing the current action thread
24+
+++++++++++++++++++++++++++++++++++
2325

24-
Accessing the current task
25-
++++++++++++++++++++++++++
26+
A function running inside a :class:`labthings.actions.ActionThread` is able to access the instance it is running in using the :meth:`labthings.current_action` function. This allows the state of the Action to be modified freely.
2627

27-
A function running inside a :class:`labthings.tasks.TaskThread` is able to access the instance it is running in using the :meth:`labthings.current_task` function. This allows the state of the Action to be modified freely.
28-
29-
.. autofunction:: labthings.current_task
28+
.. autofunction:: labthings.current_action
3029
:noindex:
3130

3231

33-
Updating task progress
34-
++++++++++++++++++++++
32+
Updating action progress
33+
++++++++++++++++++++++++
3534

36-
Some client applications may be able to display progress bars showing the progress of an action. Implementing progress updates in your actions is made easy with the :py:meth:`labthings.update_task_progress` function. This function takes a single argument, which is the action progress as an integer percent (0 - 100).
35+
Some client applications may be able to display progress bars showing the progress of an action. Implementing progress updates in your actions is made easy with the :py:meth:`labthings.update_action_progress` function. This function takes a single argument, which is the action progress as an integer percent (0 - 100).
3736

3837
If your long running function was started within a background task, this function will update the state of the corresponding action object. If your function is called outside of a long-running task (e.g. by some internal code, not the web API), then this function will silently do nothing.
3938

40-
.. autofunction:: labthings.update_task_progress
39+
.. autofunction:: labthings.update_action_progress
4140
:noindex:

src/labthings/actions/thread.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,34 @@ def __init__(self, target=None, name=None, args=None, kwargs=None, daemon=True):
7878

7979
@property
8080
def id(self):
81-
""" """
81+
"""
82+
UUID for the thread. Note this not the same as the native thread ident.
83+
"""
8284
return self._ID
8385

8486
@property
8587
def output(self):
86-
""" """
88+
"""
89+
Return value of the Action function. If the Action is still running, returns None.
90+
"""
8791
return self._return_value
8892

8993
@property
9094
def status(self):
91-
""" """
95+
"""
96+
Current running status of the thread.
97+
98+
============== =============================================
99+
Status Meaning
100+
============== =============================================
101+
``pending`` Not yet started
102+
``running`` Currently in-progress
103+
``success`` Finished without error
104+
``error`` Exception occured in thread
105+
``stopped`` Thread finished cleanly after a stop request
106+
``terminated`` Thread killed after stop request timed out
107+
============== =============================================
108+
"""
92109
return self._status
93110

94111
@property
@@ -192,7 +209,7 @@ def get(self, block=True, timeout=None):
192209
self.join(timeout=timeout)
193210
return self._return_value
194211

195-
def async_raise(self, exc_type):
212+
def _async_raise(self, exc_type):
196213
"""
197214
198215
:param exc_type:
@@ -259,7 +276,7 @@ def terminate(self, exception=ActionKilledException):
259276
"will not kill; letting thread exit gracefully."
260277
)
261278
return
262-
self.async_raise(exception)
279+
self._async_raise(exception)
263280

264281
# Wait (block) for the thread to finish closing. If the threaded function has cleanup code in a try-except,
265282
# this pause allows it to finish running before the main thread can continue.

0 commit comments

Comments
 (0)