Skip to content

Commit 6447de0

Browse files
author
Joel Collins
committed
2 parents 60c3653 + 8ebfddf commit 6447de0

26 files changed

+524
-928
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
branch = True
33
source = ./src/labthings
44
omit = .venv/*, ./src/labthings/wsgi.py, ./src/labthings/monkey.py, ./src/labthings/server/*, ./src/labthings/core/*
5-
concurrency = greenlet
5+
concurrency = thread
66

77
[report]
88
# Regexes for lines to exclude from consideration

CHANGELOG.md

Lines changed: 90 additions & 94 deletions
Large diffs are not rendered by default.

examples/components/pdf_component.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import math
33
import time
44

5+
from labthings.tasks import current_task
6+
57
"""
68
Class for our lab component functionality. This could include serial communication,
79
equipment API calls, network requests, or a "virtual" device as seen here.
@@ -44,6 +46,8 @@ def average_data(self, n: int):
4446
summed_data = self.data
4547

4648
for _ in range(n):
49+
if current_task() and current_task().stopped:
50+
return summed_data
4751
summed_data = [summed_data[i] + el for i, el in enumerate(self.data)]
4852
time.sleep(0.25)
4953

poetry.lock

Lines changed: 36 additions & 243 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "labthings"
3-
version = "0.8.0-beta.1"
3+
version = "0.8.0-beta.2"
44
description = "Python implementation of LabThings, based on the Flask microframework"
55
readme = "README.md"
66
repository = "https://github.com/labthings/python-labthings/"
@@ -18,9 +18,8 @@ marshmallow = "^3.4.0"
1818
webargs = "^6.0.0"
1919
apispec = "^3.2.0"
2020
flask-cors = "^3.0.8"
21-
gevent = ">=1.4,<21.0"
22-
gevent-websocket = "^0.10.1"
2321
zeroconf = ">=0.24.5,<0.29.0"
22+
flask-threaded-sockets = "^0.2.0"
2423

2524
[tool.poetry.dev-dependencies]
2625
pytest = "^5.4"

src/labthings/default_views/actions.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
from ..view import View
44
from ..view.marshalling import marshal_with
5+
from ..view.args import use_args
56
from ..schema import ActionSchema
67
from ..find import current_thing
8+
from .. import fields
79

810

911
class ActionQueue(View):
@@ -12,7 +14,7 @@ class ActionQueue(View):
1214
"""
1315

1416
def get(self):
15-
return ActionSchema(many=True).dump(current_thing.actions.greenlets)
17+
return ActionSchema(many=True).dump(current_thing.actions.threads)
1618

1719

1820
class ActionView(View):
@@ -38,19 +40,22 @@ def get(self, task_id):
3840

3941
return ActionSchema().dump(task)
4042

41-
def delete(self, task_id):
43+
@use_args({"timeout": fields.Int(missing=5)})
44+
def delete(self, args, task_id):
4245
"""
4346
Terminate a running task.
4447
4548
If the task is finished, deletes its entry.
4649
"""
50+
timeout = args.get("timeout", 5)
4751
task_dict = current_thing.actions.to_dict()
4852

4953
if task_id not in task_dict:
5054
return abort(404) # 404 Not Found
5155

5256
task = task_dict.get(task_id)
5357

54-
task.kill(block=True, timeout=3)
58+
# TODO: Make non-blocking?
59+
task.stop(timeout=timeout)
5560

5661
return ActionSchema().dump(task)

src/labthings/default_views/sockets.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from ..sockets import SocketSubscriber
22
from ..find import current_thing
33

4-
import gevent
54
import logging
65

76

@@ -21,7 +20,6 @@ def socket_handler(ws):
2120
response = process_socket_message(message)
2221
if response:
2322
ws.send(response)
24-
gevent.sleep(0.1)
2523
# Remove the subscriber once the loop returns
2624
current_thing.subscribers.remove(wssub)
2725
logging.info(f"Removed subscriber {wssub}")

src/labthings/default_views/tasks.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def get(self):
1818
logging.warning(
1919
"TaskList is deprecated and will be removed in a future version. Use the Actions list instead."
2020
)
21-
return TaskSchema(many=True).dump(current_thing.actions.greenlets)
21+
return TaskSchema(many=True).dump(current_thing.actions.threads)
2222

2323

2424
class TaskView(View):
@@ -64,7 +64,6 @@ def delete(self, task_id):
6464
return abort(404) # 404 Not Found
6565

6666
task = task_dict.get(task_id)
67-
68-
task.kill(block=True, timeout=3)
67+
task.stop(timeout=5)
6968

7069
return TaskSchema().dump(task)

src/labthings/labthing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from flask import url_for
2+
from flask_threaded_sockets import Sockets
23
from apispec import APISpec
34

45
# from apispec.ext.marshmallow import MarshmallowPlugin
@@ -19,7 +20,6 @@
1920
from .representations import DEFAULT_REPRESENTATIONS
2021
from .apispec import MarshmallowPlugin, rule_to_apispec_path
2122
from .td import ThingDescription
22-
from .sockets import Sockets
2323
from .event import Event
2424

2525
from .tasks import Pool
@@ -61,7 +61,7 @@ def __init__(
6161

6262
self.extensions = {}
6363

64-
self.actions = Pool() # Pool of greenlets for Actions
64+
self.actions = Pool() # Pool of threads for Actions
6565

6666
self.events = {}
6767

src/labthings/monkey.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
from gevent.monkey import patch_all
2-
3-
__all__ = ["patch_all"]
4-
5-
"""
6-
NOTE: THIS FILE IS EXCLUDED FROM OUR UNIT TESTS.
7-
8-
MONKEY PATCHING IN THE MIDDLE OF A TEST SUITE RUNNING
9-
MAY CAUSE PROBLEMS.
10-
11-
GIVEN THAT THIS MODULE IS SIMPLY A PROXY FOR GEVENTS
12-
MONKEY PATCHER, TESTSING IS FAIRLY REDUNDANT ANYWAY.
13-
14-
THIS SHOULD BE PERIODICALLY REVISITED TO MAKE SURE ITS
15-
STILL TRUE.
16-
17-
THANKS
18-
"""
1+
def patch_all(*args, **kwargs):
2+
# Here for backwards compatibility
3+
return

0 commit comments

Comments
 (0)