Skip to content

Commit

Permalink
Add an example with threaded host nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Matevz Morato committed May 3, 2024
1 parent 4453096 commit 39db2d9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions bindings/python/examples/v3/HostNodes/threaded_host_nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import depthai as dai
import time

class TestPassthrough(dai.node.ThreadedHostNode):
def __init__(self):
dai.node.ThreadedHostNode.__init__(self)
self.input = dai.Node.Input(self)
self.output = dai.Node.Output(self)
def run(self):
while self.isRunning():
buffer = self.input.get()
print("The passthrough node received a buffer!")
self.output.send(buffer)

class TestSink(dai.node.ThreadedHostNode):
def __init__(self):
dai.node.ThreadedHostNode.__init__(self)
self.input = dai.Node.Input(self)
def run(self):
while self.isRunning():
buffer = self.input.get()
print("The sync node received a buffer!")

class TestSource(dai.node.ThreadedHostNode):
def __init__(self):
dai.node.ThreadedHostNode.__init__(self)
self.output = dai.Node.Output(self)
def run(self):
while self.isRunning():
buffer = dai.Buffer()
print("The source node is sending a buffer!")
self.output.send(buffer)
time.sleep(1)

with dai.Pipeline(False) as p:
source = TestSource()
sink = TestSink()
passthrough = TestPassthrough()
source.output.link(passthrough.input)
passthrough.output.link(sink.input)
p.start()
while True:
time.sleep(1)
print("Pipeline is running...")

0 comments on commit 39db2d9

Please sign in to comment.