-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_queue.py
More file actions
43 lines (33 loc) · 918 Bytes
/
test_queue.py
File metadata and controls
43 lines (33 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Simple round-trip test for SharedMemoryQueue.
Run directly: python test_queue.py
"""
import sys
from pathlib import Path
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))
from slick_queue_py import SlickQueue
NAME = "slick_queue_py_test_shm"
SIZE = 8
ELEMENT_SIZE = 32
def main():
# create
q = SlickQueue(name=NAME, size=SIZE, element_size=ELEMENT_SIZE)
try:
# reserve one slot
idx = q.reserve(1)
# write bytes (pad or truncate to element size)
payload = b'hello-from-python'
slot = q[idx]
slot[:len(payload)] = payload
q.publish(idx, 1)
# read back
data, sz, new_idx = q.read(0)
if data is None:
print('no data')
else:
print('read:', data.rstrip(b"\\x00"))
finally:
q.close()
q.unlink()
if __name__ == '__main__':
main()