-
Notifications
You must be signed in to change notification settings - Fork 404
Expand file tree
/
Copy pathreceive_data.py
More file actions
47 lines (33 loc) · 1.14 KB
/
receive_data.py
File metadata and controls
47 lines (33 loc) · 1.14 KB
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
44
45
46
47
from dora import Node
import logging
import threading
import time
import numpy as np
import pyarrow as pa
def read_data_task(node, log):
"""Task that reads incoming events."""
while (event := node.next()) is not None:
if event["type"] == "INPUT":
print(f"info {event['value'].to_numpy()}")
del event
log.log(logging.INFO, "read_data_task done!")
def publish_task(node, log):
"""Task that publishes to a topic."""
while True:
time.sleep(1) # Publish every 1s
now = time.perf_counter_ns()
node.send_output("data", pa.array([np.uint64(now)]))
def main():
node = Node()
log = logging.getLogger(__name__)
# Create thread for read task
read_thread = threading.Thread(target=read_data_task, args=(node, log))
read_thread.start()
# Run publish task in a daemon thread (so it doesn't block main thread)
publish_thread = threading.Thread(target=publish_task, args=(node, log), daemon=True)
publish_thread.start()
# Wait for read thread to complete
read_thread.join()
log.log(logging.INFO, "done!")
if __name__ == "__main__":
main()