Skip to content

Commit 82b8d34

Browse files
committed
[feat] add python tutorial-02
1 parent 7cada4e commit 82b8d34

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

python/tutorial/MyPyGNode/MyPyNode1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313

1414
class MyPyNode1(GNode):
1515
def run(self):
16-
print("[{0}] {1}, enter MyPyNode1 run function. Sleep for 2 second ... ".format(datetime.now(), self.getName()))
16+
print("[{0}] {1}, enter MyPyNode1 run function. Sleep for 1 second ... ".format(datetime.now(), self.getName()))
1717
time.sleep(1)
1818
return CStatus()

python/tutorial/T02-Cluster.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: T02-Cluster
5+
@Time: 2025/2/22 11:40
6+
@Desc:
7+
"""
8+
9+
from PyCGraph import GNode, GPipeline, GCluster, CStatus
10+
11+
from MyPyGNode.MyPyNode1 import MyPyNode1
12+
from MyPyGNode.MyPyNode2 import MyPyNode2
13+
14+
def tutorial_cluster():
15+
b1, b2, b3 = MyPyNode1(), MyPyNode1(), MyPyNode2()
16+
b1.setName("nodeB1")
17+
b2.setName("nodeB2")
18+
b2.setLoop(3)
19+
b3.setName("nodeB3")
20+
b_cluster = GCluster()
21+
b_cluster.addGElements([b1, b2, b3])
22+
23+
pipeline = GPipeline()
24+
a, c, d = MyPyNode1(), MyPyNode2(), MyPyNode1()
25+
26+
pipeline.registerGElement(a, set(), "nodeA")
27+
pipeline.registerGElement(b_cluster, {a}, "clusterB", 2)
28+
pipeline.registerGElement(c, {a}, "nodeC")
29+
pipeline.registerGElement(d, {b_cluster, c}, "nodeD", 2)
30+
31+
pipeline.process()
32+
33+
34+
if __name__ == '__main__':
35+
tutorial_cluster()

0 commit comments

Comments
 (0)