Skip to content

Commit 7c0df27

Browse files
author
Joel Collins
committed
Removed current_task_stopped function
1 parent 6e4465f commit 7c0df27

File tree

5 files changed

+21
-36
lines changed

5 files changed

+21
-36
lines changed

examples/simple_thing.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
#!/usr/bin/env python
2-
from labthings import monkey
3-
4-
monkey.patch_all()
5-
62
import random
73
import math
84
import time
95
import logging
106
import atexit
117

12-
from labthings.server.quick import create_app
13-
from labthings.server import semantics
14-
from labthings.server.view import ActionView, PropertyView
15-
from labthings.server.find import find_component
16-
from labthings.server import fields
8+
from labthings.server.quick import create_app, semantics, find_component, fields
9+
from labthings.views import ActionView, PropertyView
1710

1811

1912
"""

src/labthings/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
# Task management functions
2323
from .tasks import current_task
24-
from .tasks import current_task_stopped
2524
from .tasks import update_task_progress
2625
from .tasks import update_task_data
2726
from .tasks import TaskKillException

src/labthings/labthing.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,14 @@ def add_view(self, view, *urls, endpoint=None, **kwargs):
378378
379379
:param view: View class
380380
:type resource: class:`labthings.views.View`
381-
:param *urls: one or more url routes to match for the resource, standard
381+
:param urls: one or more url routes to match for the resource, standard
382382
flask routing rules apply. Any url variables will be
383383
passed to the resource method as args.
384-
:type *urls: str
384+
:type urls: str
385385
:param endpoint: endpoint name (defaults to :meth:`Resource.__name__`
386386
Can be used to reference this route in :class:`fields.Url` fields
387387
:type endpoint: str
388-
:param **kwargs: kwargs to be forwarded to the constructor
388+
:param kwargs: kwargs to be forwarded to the constructor
389389
of the view.
390390
391391
Additional keyword arguments not specified above will be passed as-is
@@ -407,11 +407,20 @@ def add_view(self, view, *urls, endpoint=None, **kwargs):
407407
self.views.append((view, urls, endpoint, kwargs))
408408

409409
def view(self, *urls, **kwargs):
410-
"""
410+
"""Wraps a :class:`labthings.View` class, adding it to the LabThing.
411+
Parameters are the same as :meth:`~labthings.LabThing.add_view`.
412+
413+
Example::
414+
415+
app = Flask(__name__)
416+
labthing = labthings.LabThing(app)
411417
412-
:param *urls:
413-
:param **kwargs:
418+
@labthing.view('/properties/my_property')
419+
class Foo(labthings.views.PropertyView):
420+
schema = labthings.fields.String()
414421
422+
def get(self):
423+
return 'Hello, World!'
415424
"""
416425

417426
def decorator(cls):
@@ -494,7 +503,7 @@ def url_for(self, view, **values):
494503
Works like :func:`flask.url_for`.
495504
496505
:param view:
497-
:param **values:
506+
:param values:
498507
499508
"""
500509
if isinstance(view, str):
@@ -532,7 +541,7 @@ def build_property(
532541
:param property_object: object:
533542
:param property_name: str:
534543
:param urls: list: (Default value = None)
535-
:param **kwargs:
544+
:param kwargs:
536545
537546
"""
538547
if urls is None:
@@ -547,7 +556,7 @@ def build_action(
547556
:param action_object: object:
548557
:param action_name: str:
549558
:param urls: list: (Default value = None)
550-
:param **kwargs:
559+
:param kwargs:
551560
552561
"""
553562
if urls is None:

src/labthings/tasks/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
__all__ = [
22
"current_task",
3-
"current_task_stopped",
43
"update_task_progress",
54
"update_task_data",
65
"TaskKillException",
@@ -9,7 +8,6 @@
98

109
from .pool import (
1110
current_task,
12-
current_task_stopped,
1311
update_task_progress,
1412
update_task_data,
1513
)

src/labthings/tasks/pool.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# TODO: Handle discarding old tasks. Action views now use deques
99
class Pool:
1010
""" """
11+
1112
def __init__(self):
1213
self.threads = set()
1314

@@ -131,21 +132,6 @@ def current_task():
131132
return current_task_thread
132133

133134

134-
def current_task_stopped():
135-
"""Return True if the current task is stoppable and flagged to be stopped
136-
137-
If this function is called from outside a Task thread, it will return None.
138-
139-
140-
:returns: bool -- Is the current task scheduled to be stopped
141-
142-
"""
143-
current_task_thread = threading.current_thread()
144-
if not isinstance(current_task_thread, TaskThread):
145-
return None
146-
return current_task_thread.stopped
147-
148-
149135
def update_task_progress(progress: int):
150136
"""Update the progress of the Task in which the caller is currently running.
151137

0 commit comments

Comments
 (0)