GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [tutorial] add T07-MultiPipeline tutorial for python · feiyunwill/CGraph@51ba7fc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .gitignore
  • python
    • PyCGraph.cpp
    • tutorial
      • T07-MultiPipeline.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboardExpand all lines: .gitignore
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
/python/dist
1919
/python/PyCGraph.egg-info
2020
__pycache__
21+
*.pyi
Collapse file

‎python/PyCGraph.cpp‎

Copy file name to clipboardExpand all lines: python/PyCGraph.cpp
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ PYBIND11_MODULE(PyCGraph, m) {
3838
.def_readwrite("batch_task_enable", &UThreadPoolConfig::batch_task_enable_)
3939
.def_readwrite("monitor_enable", &UThreadPoolConfig::monitor_enable_);
4040

41+
py::class_<UThreadPool>(m, "UThreadPool")
42+
.def(py::init<CBool, const UThreadPoolConfig&>(),
43+
py::arg("autoInit") = true,
44+
py::arg("config") = UThreadPoolConfig{})
45+
.def("setConfig", &UThreadPool::setConfig,
46+
py::keep_alive<1, 2>())
47+
.def("getConfig", &UThreadPool::getConfig)
48+
.def("init", &UThreadPool::init)
49+
.def("destroy", &UThreadPool::destroy)
50+
.def("isInit", &UThreadPool::isInit);
51+
4152
py::enum_<GEngineType>(m, "GEngineType")
4253
.value("DYNAMIC", GEngineType::DYNAMIC)
4354
.value("TOPO", GEngineType::TOPO)
@@ -151,6 +162,9 @@ PYBIND11_MODULE(PyCGraph, m) {
151162
.def("hasGParam", &PyGPipeline::__hasGParam_4py,
152163
py::call_guard<py::gil_scoped_release>())
153164
.def("setUniqueThreadPoolConfig", &PyGPipeline::setUniqueThreadPoolConfig)
165+
.def("setSharedThreadPool", &PyGPipeline::setSharedThreadPool,
166+
py::call_guard<py::gil_scoped_release>(),
167+
py::keep_alive<1, 2>())
154168
.def("setGEngineType", &PyGPipeline::setGEngineType)
155169
.def("run", &PyGPipeline::run,
156170
py::call_guard<py::gil_scoped_release>())
Collapse file

‎python/tutorial/T07-MultiPipeline.py‎

Copy file name to clipboard
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
@Author: Chunel
3+
@Contact: [email protected]
4+
@File: T07-MultiPipeline
5+
@Time: 2025/4/1 23:37
6+
@Desc:
7+
"""
8+
9+
from PyCGraph import GPipeline, UThreadPoolConfig, UThreadPool
10+
11+
from MyGNode.MyNode1 import MyNode1
12+
from MyGNode.MyNode2 import MyNode2
13+
14+
15+
def async_pipeline_1(pipeline: GPipeline):
16+
a, b, c, d = MyNode1(), MyNode2(), MyNode1(), MyNode2()
17+
18+
pipeline.registerGElement(a, set(), "node1A")
19+
pipeline.registerGElement(b, {a}, "node1B")
20+
pipeline.registerGElement(c, {a}, "node1C")
21+
pipeline.registerGElement(d, {a}, "node1D")
22+
23+
return pipeline.asyncProcess(3)
24+
25+
26+
def async_pipeline_2(pipeline: GPipeline):
27+
a, b, c = MyNode1(), MyNode2(), MyNode1()
28+
29+
pipeline.registerGElement(a, set(), "node2A")
30+
pipeline.registerGElement(b, {a}, "node2B")
31+
pipeline.registerGElement(c, {b}, "node2C")
32+
33+
return pipeline.asyncProcess(5)
34+
35+
36+
def tutorial_multi_pipeline():
37+
pipeline1, pipeline2 = GPipeline(), GPipeline()
38+
39+
config = UThreadPoolConfig()
40+
config.default_thread_size = 4
41+
config.max_thread_size = 4
42+
config.monitor_enable = False
43+
pool = UThreadPool(True, config)
44+
45+
pipeline1.setSharedThreadPool(pool)
46+
pipeline2.setSharedThreadPool(pool)
47+
48+
result1 = async_pipeline_1(pipeline1)
49+
result2 = async_pipeline_2(pipeline2)
50+
51+
result1.wait()
52+
result2.wait()
53+
54+
55+
if __name__ == '__main__':
56+
tutorial_multi_pipeline()

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.