appose 0.6.0__tar.gz → 0.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {appose-0.6.0/src/appose.egg-info → appose-0.7.0}/PKG-INFO +1 -1
- {appose-0.6.0 → appose-0.7.0}/pyproject.toml +1 -1
- {appose-0.6.0 → appose-0.7.0}/src/appose/python_worker.py +10 -2
- {appose-0.6.0 → appose-0.7.0/src/appose.egg-info}/PKG-INFO +1 -1
- {appose-0.6.0 → appose-0.7.0}/tests/test_appose.py +15 -4
- {appose-0.6.0 → appose-0.7.0}/LICENSE.txt +0 -0
- {appose-0.6.0 → appose-0.7.0}/README.md +0 -0
- {appose-0.6.0 → appose-0.7.0}/setup.cfg +0 -0
- {appose-0.6.0 → appose-0.7.0}/src/appose/__init__.py +0 -0
- {appose-0.6.0 → appose-0.7.0}/src/appose/environment.py +0 -0
- {appose-0.6.0 → appose-0.7.0}/src/appose/paths.py +0 -0
- {appose-0.6.0 → appose-0.7.0}/src/appose/service.py +0 -0
- {appose-0.6.0 → appose-0.7.0}/src/appose/types.py +0 -0
- {appose-0.6.0 → appose-0.7.0}/src/appose.egg-info/SOURCES.txt +0 -0
- {appose-0.6.0 → appose-0.7.0}/src/appose.egg-info/dependency_links.txt +0 -0
- {appose-0.6.0 → appose-0.7.0}/src/appose.egg-info/requires.txt +0 -0
- {appose-0.6.0 → appose-0.7.0}/src/appose.egg-info/top_level.txt +0 -0
- {appose-0.6.0 → appose-0.7.0}/tests/test_shm.py +0 -0
- {appose-0.6.0 → appose-0.7.0}/tests/test_types.py +0 -0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "appose"
|
7
|
-
version = "0.
|
7
|
+
version = "0.7.0"
|
8
8
|
description = "Appose: multi-language interprocess cooperation with shared memory."
|
9
9
|
license = "BSD-2-Clause"
|
10
10
|
authors = [{name = "Appose developers"}]
|
@@ -51,7 +51,10 @@ from appose.types import Args, _set_worker, decode, encode
|
|
51
51
|
|
52
52
|
|
53
53
|
class Task:
|
54
|
-
def __init__(
|
54
|
+
def __init__(
|
55
|
+
self, worker: "Worker", uuid: str, script: str, inputs: Args | None = None
|
56
|
+
) -> None:
|
57
|
+
self._worker = worker
|
55
58
|
self._uuid = uuid
|
56
59
|
self._script = script
|
57
60
|
self._inputs = inputs
|
@@ -62,6 +65,9 @@ class Task:
|
|
62
65
|
self.outputs = {}
|
63
66
|
self.cancel_requested = False
|
64
67
|
|
68
|
+
def export(self, **kwargs):
|
69
|
+
self._worker.exports.update(kwargs)
|
70
|
+
|
65
71
|
def update(
|
66
72
|
self,
|
67
73
|
message: str | None = None,
|
@@ -96,6 +102,7 @@ class Task:
|
|
96
102
|
try:
|
97
103
|
# Populate script bindings.
|
98
104
|
binding = {"task": self}
|
105
|
+
binding.update(self._worker.exports)
|
99
106
|
if self._inputs is not None:
|
100
107
|
binding.update(self._inputs)
|
101
108
|
|
@@ -184,6 +191,7 @@ class Worker:
|
|
184
191
|
def __init__(self):
|
185
192
|
self.tasks = {}
|
186
193
|
self.queue: list[Task] = []
|
194
|
+
self.exports = {}
|
187
195
|
self.running = True
|
188
196
|
|
189
197
|
# Flag this process as a worker, not a service.
|
@@ -223,7 +231,7 @@ class Worker:
|
|
223
231
|
script = request.get("script")
|
224
232
|
inputs = request.get("inputs")
|
225
233
|
queue = request.get("queue")
|
226
|
-
task = Task(uuid, script, inputs)
|
234
|
+
task = Task(self, uuid, script, inputs)
|
227
235
|
self.tasks[uuid] = task
|
228
236
|
if queue == "main":
|
229
237
|
# Add the task to the main thread queue.
|
@@ -57,10 +57,11 @@ while v != 1:
|
|
57
57
|
task.outputs["result"] = time
|
58
58
|
"""
|
59
59
|
|
60
|
-
|
60
|
+
calc_sqrt_python = """
|
61
61
|
from math import sqrt
|
62
62
|
def sqrt_age(age):
|
63
63
|
return sqrt(age)
|
64
|
+
task.export(sqrt_age=sqrt_age)
|
64
65
|
task.outputs["result"] = sqrt_age(age)
|
65
66
|
"""
|
66
67
|
|
@@ -103,16 +104,22 @@ def test_service_startup_failure():
|
|
103
104
|
) == str(e)
|
104
105
|
|
105
106
|
|
106
|
-
def
|
107
|
+
def test_scope_python():
|
107
108
|
env = appose.system()
|
108
109
|
with env.python() as service:
|
109
110
|
maybe_debug(service)
|
110
|
-
task = service.task(
|
111
|
-
task.start()
|
111
|
+
task = service.task(calc_sqrt_python, {"age": 100})
|
112
112
|
task.wait_for()
|
113
|
+
assert TaskStatus.COMPLETE == task.status
|
113
114
|
result = round(task.outputs.get("result"))
|
114
115
|
assert result == 10
|
115
116
|
|
117
|
+
task = service.task("task.outputs['result'] = sqrt_age(age)", {"age": 81})
|
118
|
+
task.wait_for()
|
119
|
+
assert TaskStatus.COMPLETE == task.status
|
120
|
+
result = round(task.outputs.get("result"))
|
121
|
+
assert result == 9
|
122
|
+
|
116
123
|
|
117
124
|
def test_main_thread_queue_groovy():
|
118
125
|
env = appose.system()
|
@@ -123,11 +130,13 @@ def test_main_thread_queue_groovy():
|
|
123
130
|
|
124
131
|
task = service.task(main_thread_check_groovy, queue="main")
|
125
132
|
task.wait_for()
|
133
|
+
assert TaskStatus.COMPLETE == task.status
|
126
134
|
thread = task.outputs.get("thread")
|
127
135
|
assert thread == "main"
|
128
136
|
|
129
137
|
task = service.task(main_thread_check_groovy)
|
130
138
|
task.wait_for()
|
139
|
+
assert TaskStatus.COMPLETE == task.status
|
131
140
|
thread = task.outputs.get("thread")
|
132
141
|
assert thread != "main"
|
133
142
|
|
@@ -137,11 +146,13 @@ def test_main_thread_queue_python():
|
|
137
146
|
with env.python() as service:
|
138
147
|
task = service.task(main_thread_check_python, queue="main")
|
139
148
|
task.wait_for()
|
149
|
+
assert TaskStatus.COMPLETE == task.status
|
140
150
|
thread = task.outputs.get("thread")
|
141
151
|
assert thread == "MainThread"
|
142
152
|
|
143
153
|
task = service.task(main_thread_check_python)
|
144
154
|
task.wait_for()
|
155
|
+
assert TaskStatus.COMPLETE == task.status
|
145
156
|
thread = task.outputs.get("thread")
|
146
157
|
assert thread != "MainThread"
|
147
158
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|