Skip to content

Commit 7cada4e

Browse files
committed
[feat] add python tutorial0 & 1
1 parent 4335b26 commit 7cada4e

File tree

8 files changed

+126
-0
lines changed

8 files changed

+126
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
/python/build
1818
/python/dist
1919
/python/PyCGraph.egg-info
20+
__pycache__
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: HelloCGraphPyNode
5+
@Time: 2025/2/21 23:30
6+
@Desc:
7+
"""
8+
9+
from PyCGraph import GNode, CStatus
10+
11+
class HelloCGraphPyNode(GNode):
12+
def run(self):
13+
print("Hello PyCGraph")
14+
return CStatus()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: MyPyNode1
5+
@Time: 2025/2/21 23:47
6+
@Desc:
7+
"""
8+
9+
from datetime import datetime
10+
import time
11+
12+
from PyCGraph import GNode, CStatus
13+
14+
class MyPyNode1(GNode):
15+
def run(self):
16+
print("[{0}] {1}, enter MyPyNode1 run function. Sleep for 2 second ... ".format(datetime.now(), self.getName()))
17+
time.sleep(1)
18+
return CStatus()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: MyPyNode2
5+
@Time: 2025/2/21 23:48
6+
@Desc:
7+
"""
8+
9+
from datetime import datetime
10+
import time
11+
12+
from PyCGraph import GNode, CStatus
13+
14+
class MyPyNode2(GNode):
15+
def init(self):
16+
print("[INIT] [{0}], enter MyNode2 init function.".format(self.getName()))
17+
return CStatus()
18+
19+
def run(self):
20+
print("[{0}] {1}, enter MyPyNode2 run function. Sleep for 2 second ... ".format(datetime.now(), self.getName()))
21+
time.sleep(2)
22+
return CStatus()
23+
24+
def destroy(self):
25+
print("[DESTROY] [{0}], enter MyNode2 destroy function.".format(self.getName()))
26+
return CStatus()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: __init__.py
5+
@Time: 2025/2/21 23:26
6+
@Desc:
7+
"""

python/tutorial/T00-HelloCGraph.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: T00-HelloCGraph
5+
@Time: 2025/2/21 23:25
6+
@Desc:
7+
"""
8+
9+
from PyCGraph import GNode, GPipeline, CStatus
10+
11+
from MyPyGNode.HelloCGraphPyNode import HelloCGraphPyNode
12+
13+
def tutorial_hello_cgraph():
14+
pipeline = GPipeline()
15+
hcg = HelloCGraphPyNode()
16+
pipeline.registerGElement(hcg)
17+
pipeline.process()
18+
19+
20+
if __name__ == '__main__':
21+
tutorial_hello_cgraph()

python/tutorial/T01-Simple.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: T01-Simple
5+
@Time: 2025/2/21 23:57
6+
@Desc:
7+
"""
8+
9+
from PyCGraph import GNode, GPipeline, CStatus
10+
11+
from MyPyGNode.MyPyNode1 import MyPyNode1
12+
from MyPyGNode.MyPyNode2 import MyPyNode2
13+
14+
def tutorial_simple():
15+
pipeline = GPipeline()
16+
a, b, c, d = MyPyNode1(), MyPyNode2(), MyPyNode1(), MyPyNode2()
17+
18+
pipeline.registerGElement(a, set(), "nodeA")
19+
pipeline.registerGElement(b, {a}, "nodeB")
20+
pipeline.registerGElement(c, {a}, "nodeC")
21+
pipeline.registerGElement(d, {b, c}, "nodeD")
22+
pipeline.init()
23+
24+
for i in range(0, 3):
25+
status = pipeline.run()
26+
print("==== tutorial_simple, loop: {0}, and run status = {1}".format(i + 1, status.getCode()))
27+
28+
pipeline.destroy()
29+
30+
31+
if __name__ == '__main__':
32+
tutorial_simple()

python/tutorial/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: __init__.py
5+
@Time: 2025/2/21 22:26
6+
@Desc:
7+
"""

0 commit comments

Comments
 (0)