Skip to content

Commit f57f513

Browse files
author
Joel Collins
committed
Updated documentation
1 parent c140e64 commit f57f513

File tree

10 files changed

+61
-22
lines changed

10 files changed

+61
-22
lines changed

docs/advanced_usage/components.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Components
2+
==========
3+
4+
*Documentation to be written*

docs/advanced_usage/encoders.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Data encoders
2+
=============
3+
4+
*Documentation to be written*

docs/advanced_usage/extensions.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
LabThing Extensions
2+
===================
3+
4+
*Documentation to be written*

docs/advanced_usage/index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Advanced usage
2+
==============
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
:caption: Contents:
7+
8+
view_class.rst
9+
components.rst
10+
encoders.rst
11+
extensions.rst

docs/advanced_usage/view_class.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
View classes
2+
============
3+
4+
*Documentation to be written*
5+
6+
Base View
7+
---------
8+
9+
Property View
10+
-------------
11+
12+
Action View
13+
-----------
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
Action tasks
2-
============
1+
Action threads
2+
==============
33

44
Many actions in your LabThing may perform tasks that take a long time (compared to the expected response time of a web request). For example, if you were to implement a timelapse action, this inherently runs over a long time.
55

66
This introduces a couple of problems. Firstly, a request that triggers a long function will, by default, block the Python interpreter for the duration of the function. This usually causes the connection to timeout, and the response will never be revieved.
77

8-
Tasks are introduced to manage long-running functions in a way that does not block HTTP requests. Any API Action will automatically run as a task.
8+
Tasks are introduced to manage long-running functions in a way that does not block HTTP requests. Any API Action will automatically run as a background thread.
99

10-
Internally, the :class:`labthings.LabThing` object stores a list of all requested actions, and their states. This state stores the running status of the action (if itis idle, running, error, or success), information about the start and end times, a unique task ID, and, upon completion, the return value of the long-running function.
10+
Internally, the :class:`labthings.LabThing` object stores a list of all requested actions, and their states. This state stores the running status of the action (if itis idle, running, error, or success), information about the start and end times, a unique ID, and, upon completion, the return value of the long-running function.
1111

12-
By using tasks, a function can be started in the background, and it's return value fetched at a later time once it has reported success. If a long-running action is started by some client, it should note the ID returned in the action state JSON, and use this to periodically check on the status of that particular action.
12+
By using threads, a function can be started in the background, and it's return value fetched at a later time once it has reported success. If a long-running action is started by some client, it should note the ID returned in the action state JSON, and use this to periodically check on the status of that particular action.
1313

14-
API routes have been created to allow checking the state of all actions (GET ``/actions``), a particular task by ID (GET ``/actions/<action_id>``), and terminating or removing individual tasks (DELETE ``/actions/<action_id>``).
14+
API routes have been created to allow checking the state of all actions (GET ``/actions``), a particular action by ID (GET ``/actions/<action_id>``), and terminating or removing individual actions (DELETE ``/actions/<action_id>``).
1515

16-
All Actions will return a serialized representation of the task, when your POST request returns. If the task completes within a default timeout period (usually 1 second) then the completed Action representation will be returned. If the task is still running after this timeout period, the "in-progress" Action representation will be returned. The final output value can then be retrieved at a later time.
16+
All actions will return a serialized representation of the action state when your POST request returns. If the action completes within a default timeout period (usually 1 second) then the completed action representation will be returned. If the action is still running after this timeout period, the "in-progress" action representation will be returned. The final output value can then be retrieved at a later time.
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

2020
.. autoclass:: labthings.actions.ActionThread
21+
:noindex:
2122
:members:
2223

2324
Accessing the current action thread
@@ -34,7 +35,7 @@ Updating action progress
3435

3536
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).
3637

37-
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.
38+
If your long running function was started within a :class:`labthings.actions.ActionThread`, this function will update the state of the corresponding :class:`labthings.actions.ActionThread` instance. If your function is called outside of an :class:`labthings.actions.ActionThread` (e.g. by some internal code, not the web API), then this function will silently do nothing.
3839

3940
.. autofunction:: labthings.update_action_progress
40-
:noindex:
41+
:noindex:

docs/basic_usage/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Basic usage
77

88
app_thing_server.rst
99
http_api_structure.rst
10-
websocket_api_structure.rst
10+
ws_api_structure.rst
1111
serialising.rst
12-
action_tasks.rst
12+
action_threads.rst
1313
synchronisation.rst

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Welcome to Python-LabThings' documentation!
99
quickstart.rst
1010

1111
basic_usage/index.rst
12+
advanced_usage/index.rst
1213

1314
api.rst
1415

src/labthings/actions/pool.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def current_action():
123123
If this function is called from outside an ActionThread, it will return None.
124124
125125
126-
:returns: ActionThread -- Currently running ActionThread.
126+
:returns: :class:`labthings.actions.ActionThread` -- Currently running ActionThread.
127127
128128
"""
129129
current_action_thread = threading.current_thread()
@@ -133,12 +133,11 @@ def current_action():
133133

134134

135135
def update_action_progress(progress: int):
136-
"""Update the progress of the Task in which the caller is currently running.
136+
"""Update the progress of the ActionThread in which the caller is currently running.
137137
138-
If this function is called from outside a Task thread, it will do nothing.
138+
If this function is called from outside an ActionThread, it will do nothing.
139139
140-
:param progress: int
141-
:param progress: int:
140+
:param progress: int: Action progress, in percent (0-100)
142141
143142
"""
144143
if current_action():
@@ -148,12 +147,11 @@ def update_action_progress(progress: int):
148147

149148

150149
def update_action_data(data: dict):
151-
"""Update the data of the Task in which the caller is currently running.
150+
"""Update the data of the ActionThread in which the caller is currently running.
152151
153-
If this function is called from outside a Task thread, it will do nothing.
152+
If this function is called from outside an ActionThread, it will do nothing.
154153
155-
:param data: dict
156-
:param data: dict:
154+
:param data: dict: Action data dictionary
157155
158156
"""
159157
if current_action():

src/labthings/actions/thread.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ def status(self):
110110

111111
@property
112112
def dead(self):
113-
""" """
113+
"""
114+
Has the thread finished, by any means (return, exception, termination).
115+
"""
114116
return not self.is_alive()
115117

116118
@property
@@ -120,8 +122,9 @@ def stopped(self):
120122

121123
def update_progress(self, progress: int):
122124
"""
125+
Update the progress of the ActionThread.
123126
124-
:param progress: int:
127+
:param progress: int: Action progress, in percent (0-100)
125128
126129
"""
127130
# Update progress of the task

0 commit comments

Comments
 (0)