Skip to content

Commit

Permalink
Make appose.SharedMemory and appose.NDArray work
Browse files Browse the repository at this point in the history
So that these classes are in the same package (the base one)
as the Java codebase's equivalents.

And so that people don't need to know to import SharedMemory from
multiprocessing.shared_memory, which is kind of a keyboardful.
  • Loading branch information
ctrueden committed Jul 18, 2024
1 parent 51b6b0c commit 8c2748e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/appose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def task_listener(event):
from pathlib import Path

from .environment import Builder, Environment
from .types import NDArray, SharedMemory # noqa: F401


def base(directory: Path) -> Builder:
Expand Down
7 changes: 2 additions & 5 deletions tests/test_shm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@
# #L%
###

from multiprocessing.shared_memory import SharedMemory

import appose
from appose.service import TaskStatus
from appose.types import NDArray

ndarray_inspect = """
task.outputs["size"] = data.shm.size
Expand All @@ -45,11 +42,11 @@ def test_ndarray():
env = appose.system()
with env.python() as service:
# Construct the data.
shm = SharedMemory(create=True, size=2 * 2 * 20 * 25)
shm = appose.SharedMemory(create=True, size=2 * 2 * 20 * 25)
shm.buf[0] = 123
shm.buf[456] = 78
shm.buf[1999] = 210
data = NDArray("uint16", [2, 20, 25], shm)
data = appose.NDArray("uint16", [2, 20, 25], shm)

# Run the task.
task = service.task(ndarray_inspect, {"data": data})
Expand Down
5 changes: 2 additions & 3 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest
from multiprocessing.shared_memory import SharedMemory

import appose

Expand Down Expand Up @@ -66,7 +65,7 @@ def test_encode(self):
"numbers": self.NUMBERS,
"words": self.WORDS,
}
ndarray = appose.types.NDArray("float32", [2, 20, 25])
ndarray = appose.NDArray("float32", [2, 20, 25])
shm_name = ndarray.shm.name
data["ndArray"] = ndarray
json_str = appose.types.encode(data)
Expand All @@ -76,7 +75,7 @@ def test_encode(self):
ndarray.shm.unlink()

def test_decode(self):
shm = SharedMemory(create=True, size=4000)
shm = appose.SharedMemory(create=True, size=4000)
shm_name = shm.name
data = appose.types.decode(self.JSON.replace("SHM_NAME", shm_name))
self.assertIsNotNone(data)
Expand Down

0 comments on commit 8c2748e

Please sign in to comment.