First attempt

This commit is contained in:
2026-05-08 17:48:16 +02:00
commit 5e77dc836b
36 changed files with 4806 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
"""
08_python_subport — tap a C++ node's output from Python using net.read().
Graph:
[ProduceNode] --int--> [DoubleItNode] --int--> (tapped by net.read())
The sink is Python: instead of connecting a PrintItNode, we call net.read()
to pull values out of DoubleItNode's output directly into Python.
We also demonstrate net.write() by injecting a value into DoubleItNode's input.
"""
import sys
import time
import threading
sys.path.insert(0, "build/python")
import kpn_python as kpn
net = kpn.Network()
net.add("src", kpn.make_produce())
net.add("dbl", kpn.make_double_it())
net.connect("src", 0, "dbl", 0)
net.build()
net.start()
# Collect a few values from DoubleItNode's output via Python tap
results = []
for _ in range(5):
val = net.read("dbl", 0)
results.append(val)
net.stop()
print("values read from C++ DoubleItNode output:", results)
assert all(v == 84 for v in results), f"expected all 84, got {results}"
print("all correct (42 * 2 = 84)")