Skip to content

Commit 8ebfddf

Browse files
committed
Added current_task_stopped shortcut function
1 parent 70342ff commit 8ebfddf

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/labthings/tasks/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
__all__ = [
22
"Pool",
33
"current_task",
4+
"current_task_stopped",
45
"update_task_progress",
56
"update_task_data",
67
"TaskKillException",
@@ -10,6 +11,7 @@
1011
from .pool import (
1112
Pool,
1213
current_task,
14+
current_task_stopped,
1315
update_task_progress,
1416
update_task_data,
1517
)

src/labthings/tasks/pool.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ def current_task():
8888
return current_task_thread
8989

9090

91+
def current_task_stopped():
92+
"""Return True if the current task is stoppable and flagged to be stopped
93+
94+
If this function is called from outside a Task thread, it will return None.
95+
96+
Returns:
97+
bool -- Is the current task scheduled to be stopped
98+
"""
99+
current_task_thread = threading.current_thread()
100+
if not isinstance(current_task_thread, TaskThread):
101+
return None
102+
return current_task_thread.stopped
103+
104+
91105
def update_task_progress(progress: int):
92106
"""Update the progress of the Task in which the caller is currently running.
93107

0 commit comments

Comments
 (0)