forked from ChunelFeng/CGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT12-Function.py
More file actions
55 lines (40 loc) · 1.48 KB
/
T12-Function.py
File metadata and controls
55 lines (40 loc) · 1.48 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
48
49
50
51
52
53
54
55
"""
@Author: Chunel
@Contact: chunel@foxmail.com
@File: T12-Function
@Time: 2025/4/13 18:46
@Desc:
"""
import time
from PyCGraph import GPipeline, GFunction, CFunctionType, CStatus
from MyGNode.MyNode1 import MyNode1
from MyGNode.MyWriteParamNode import MyWriteParamNode
from MyParams.MyParam import MyParam
def c_function_run():
print('enter c_function_run, sleep for 1s')
time.sleep(1)
return CStatus()
def d_function_init(d: GFunction):
print('[{0}] do init function....'.format(d.getName()))
return CStatus()
def d_function_run(d: GFunction, num: int):
# get GParam info in GFunction
param: MyParam = d.getGParamWithNoEmpty('param1')
param.count += num
print('[{0}] do run function, count is {1}, value is {2}'.format(
d.getName(), param.count, param.value))
return CStatus()
def tutorial_function():
pipeline = GPipeline()
a, b = MyNode1(), MyWriteParamNode()
c_function, d_function = GFunction(), GFunction()
c_function.setFunction(CFunctionType.RUN, c_function_run)
d_function.setFunction(CFunctionType.INIT, lambda: d_function_init(d_function))
d_function.setFunction(CFunctionType.RUN, lambda: d_function_run(d_function, 10))
pipeline.registerGElement(a, set(), "nodeA")
pipeline.registerGElement(b, {a}, "nodeB")
pipeline.registerGElement(c_function, {b}, "functionC")
pipeline.registerGElement(d_function, {c_function}, "nodeD")
pipeline.process()
if __name__ == '__main__':
tutorial_function()