celestialflow 3.0.4__tar.gz → 3.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- celestialflow-3.0.5/PKG-INFO +340 -0
- celestialflow-3.0.5/README.md +315 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/pyproject.toml +1 -1
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/__init__.py +9 -2
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/static/css/dashboard.css +87 -141
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/static/js/main.js +21 -14
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/static/js/task_structure.js +31 -96
- celestialflow-3.0.5/src/celestialflow/static/js/task_topology.js +54 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/task_graph.py +17 -16
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/task_logging.py +6 -8
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/task_manage.py +15 -4
- celestialflow-3.0.5/src/celestialflow/task_nodes.py +290 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/task_queue.py +28 -12
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/task_report.py +3 -3
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/task_tools.py +31 -74
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/task_web.py +2 -2
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/templates/index.html +42 -32
- celestialflow-3.0.5/src/celestialflow.egg-info/PKG-INFO +340 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/tests/test_graph.py +11 -5
- {celestialflow-3.0.4 → celestialflow-3.0.5}/tests/test_nodes.py +106 -22
- {celestialflow-3.0.4 → celestialflow-3.0.5}/tests/test_structure.py +18 -11
- celestialflow-3.0.4/PKG-INFO +0 -300
- celestialflow-3.0.4/README.md +0 -275
- celestialflow-3.0.4/src/celestialflow/static/js/task_topology.js +0 -11
- celestialflow-3.0.4/src/celestialflow/task_nodes.py +0 -161
- celestialflow-3.0.4/src/celestialflow.egg-info/PKG-INFO +0 -300
- {celestialflow-3.0.4 → celestialflow-3.0.5}/setup.cfg +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/static/css/base.css +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/static/css/errors.css +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/static/css/inject.css +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/static/favicon.ico +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/static/js/task_errors.js +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/static/js/task_injection.js +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/static/js/task_statuses.js +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/static/js/utils.js +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/task_progress.py +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/task_structure.py +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow/task_types.py +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow.egg-info/SOURCES.txt +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow.egg-info/dependency_links.txt +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow.egg-info/entry_points.txt +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow.egg-info/requires.txt +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/src/celestialflow.egg-info/top_level.txt +0 -0
- {celestialflow-3.0.4 → celestialflow-3.0.5}/tests/test_manage.py +0 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: celestialflow
|
|
3
|
+
Version: 3.0.5
|
|
4
|
+
Summary: A flexible GRAPH-based task orchestration framework.
|
|
5
|
+
Author-email: Mr-xiaotian <mingxiaomingtian@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Mr-xiaotian/CelestialFlow
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/Mr-xiaotian/CelestialFlow/issues
|
|
9
|
+
Keywords: workflow,task,graph,async,CelestialFlow
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Framework :: FastAPI
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: tqdm
|
|
18
|
+
Requires-Dist: loguru
|
|
19
|
+
Requires-Dist: fastapi
|
|
20
|
+
Requires-Dist: uvicorn
|
|
21
|
+
Requires-Dist: requests
|
|
22
|
+
Requires-Dist: networkx
|
|
23
|
+
Requires-Dist: redis
|
|
24
|
+
Requires-Dist: jinja2
|
|
25
|
+
|
|
26
|
+
# CelestialFlow ——一个轻量级、可并行、基于图结构的 Python 任务调度框架
|
|
27
|
+
|
|
28
|
+
<p align="center">
|
|
29
|
+
<img src="https://raw.githubusercontent.com/Mr-xiaotian/CelestialFlow/main/img/logo.png" width="1080" alt="CelestialFlow Logo">
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
<p align="center">
|
|
33
|
+
<a href="https://pypi.org/project/celestialflow/"><img src="https://badge.fury.io/py/celestialflow.svg"></a>
|
|
34
|
+
<a href="https://pepy.tech/projects/celestialflow"><img src="https://static.pepy.tech/personalized-badge/celestialflow?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads"></a>
|
|
35
|
+
<a href="https://pypi.org/project/celestialflow/"><img src="https://img.shields.io/pypi/l/celestialflow.svg"></a>
|
|
36
|
+
<a href="https://pypi.org/project/celestialflow/"><img src="https://img.shields.io/pypi/pyversions/celestialflow.svg"></a>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
**CelestialFlow** 是一个轻量级但功能完全体的任务流框架,适合需要“灵活拓扑 + 多执行模式 + 可视化监控”的中/大型 Python 任务系统。
|
|
40
|
+
|
|
41
|
+
- 相比 Airflow/Dagster 更轻、更快开始
|
|
42
|
+
- 相比 multiprocessing/threading 更结构化,可直接表达 loop / complete graph 等复杂依赖
|
|
43
|
+
|
|
44
|
+
框架的基本单元为 **TaskStage**(由 `TaskManager` 派生),每个 stage 内部绑定一个独立的执行函数,并支持四种运行模式:
|
|
45
|
+
|
|
46
|
+
* **线性(serial)**
|
|
47
|
+
* **多线程(thread)**
|
|
48
|
+
* **多进程(process)**
|
|
49
|
+
* **协程(async)**
|
|
50
|
+
|
|
51
|
+
每个 stage 均可独立运行,也可作为节点互相连接,形成具有上游与下游依赖关系的任务图(**TaskGraph**)。下游 stage 会自动接收上游执行完成的结果作为输入,从而实现数据的流动与传递。
|
|
52
|
+
|
|
53
|
+
在图级别上,TaskGraph 支持两种布局模式:
|
|
54
|
+
|
|
55
|
+
* **线性执行(serial layout)**:前一节点执行完毕后再启动下一节点(下游节点可提前接收任务但不会立即执行)。
|
|
56
|
+
* **并行执行(process layout)**:所有节点同时启动运行,由队列自动协调任务传递与依赖顺序。
|
|
57
|
+
|
|
58
|
+
TaskGraph 能构建完整的 **有向图结构(Directed Graph)**,不仅支持传统的有向无环图(DAG),也能灵活表达 **环形(loop)** 与 **复杂交叉** 的任务依赖。
|
|
59
|
+
|
|
60
|
+
在此基础上项目支持 Web 可视化与通过 Redis 外接go代码,弥补 Python 在cpu密集任务上速度过慢的问题。
|
|
61
|
+
|
|
62
|
+
## 项目结构(Project Structure)
|
|
63
|
+
|
|
64
|
+
```mermaid
|
|
65
|
+
flowchart LR
|
|
66
|
+
|
|
67
|
+
%% ===== TaskGraph =====
|
|
68
|
+
subgraph TG[TaskGraph]
|
|
69
|
+
direction LR
|
|
70
|
+
|
|
71
|
+
S1[TaskStage A]
|
|
72
|
+
S2[TaskStage B]
|
|
73
|
+
S3[TaskStage C]
|
|
74
|
+
S4[TaskStage D]
|
|
75
|
+
|
|
76
|
+
T1[Last Stage]
|
|
77
|
+
T2[Next Stage]
|
|
78
|
+
|
|
79
|
+
TS[[TaskSplitter]]
|
|
80
|
+
TRSI1[/TaskRedisSink/]
|
|
81
|
+
TRSI2[/TaskRedisSink/]
|
|
82
|
+
TRSO[/TaskRedisSource/]
|
|
83
|
+
TRA[/TaskRedisAck/]
|
|
84
|
+
|
|
85
|
+
RE1[(Redis)]
|
|
86
|
+
RE2[(Redis)]
|
|
87
|
+
G1((GoWorker))
|
|
88
|
+
G2((GoWorker))
|
|
89
|
+
|
|
90
|
+
S1 --> S2 --> S3 --> S1
|
|
91
|
+
S1 --> S4
|
|
92
|
+
|
|
93
|
+
T1 -->|1 task| TS
|
|
94
|
+
TS -->|N task| T2
|
|
95
|
+
|
|
96
|
+
TRSI1 -.-> RE1 -.-> TRSO
|
|
97
|
+
TRSI2 -.->|task| RE2 -.->|task| G1
|
|
98
|
+
G2 -.->|result| RE2 -.->|result| TRA
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
%% 美化 TaskGraph 外框
|
|
103
|
+
style TG fill:#e8f2ff,stroke:#6b93d6,stroke-width:2px,color:#0b1e3f,rx:10px,ry:10px
|
|
104
|
+
|
|
105
|
+
%% 统一美化格式
|
|
106
|
+
classDef blueNode fill:#ffffff,stroke:#6b93d6,rx:6px,ry:6px;
|
|
107
|
+
|
|
108
|
+
%% 美化 TaskStages
|
|
109
|
+
class S1,S2,S3,S4 blueNode;
|
|
110
|
+
class T1,T2 blueNode;
|
|
111
|
+
|
|
112
|
+
%% 美化 特殊Stage
|
|
113
|
+
class TS,TRA,TRSI1,TRSI2,TRSO blueNode;
|
|
114
|
+
|
|
115
|
+
%% 美化 外部结构
|
|
116
|
+
class RE1,RE2,G1,G2 blueNode;
|
|
117
|
+
|
|
118
|
+
%% ===== WebUI =====
|
|
119
|
+
subgraph W[WebUI]
|
|
120
|
+
JS
|
|
121
|
+
HTML
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
style W fill:#ffeaf0,stroke:#d66b8c,stroke-width:2px,rx:10px,ry:10px
|
|
125
|
+
style JS fill:#ffffff,stroke:#d66b8c,rx:5px,ry:5px
|
|
126
|
+
style HTML fill:#ffffff,stroke:#d66b8c,rx:5px,ry:5px
|
|
127
|
+
|
|
128
|
+
R[TaskWeb]
|
|
129
|
+
style R fill:#f0e9ff,stroke:#8a6bc9,stroke-width:2px,rx:8px,ry:8px
|
|
130
|
+
|
|
131
|
+
%% ===== Links =====
|
|
132
|
+
TG --> R
|
|
133
|
+
R --> TG
|
|
134
|
+
R --> W
|
|
135
|
+
W --> R
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## 快速开始(Quick Start)
|
|
140
|
+
|
|
141
|
+
安装 CelestialFlow:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
pip install celestialflow
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
一个简单的可运行代码:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from celestialflow import TaskManager, TaskGraph
|
|
151
|
+
|
|
152
|
+
def add(x, y):
|
|
153
|
+
return x + y
|
|
154
|
+
|
|
155
|
+
def square(x):
|
|
156
|
+
return x ** 2
|
|
157
|
+
|
|
158
|
+
if __name__ == "__main__":
|
|
159
|
+
# 定义两个任务节点
|
|
160
|
+
stage1 = TaskManager(add, execution_mode="thread", unpack_task_args=True)
|
|
161
|
+
stage2 = TaskManager(square, execution_mode="thread")
|
|
162
|
+
|
|
163
|
+
# 构建任务图结构
|
|
164
|
+
stage1.set_graph_context([stage2], stage_mode="process", stage_name="Adder")
|
|
165
|
+
stage2.set_graph_context([], stage_mode="process", stage_name="Squarer")
|
|
166
|
+
graph = TaskGraph([stage1])
|
|
167
|
+
|
|
168
|
+
# 初始化任务并启动
|
|
169
|
+
graph.start_graph({stage1.get_stage_tag(): [(1, 2), (3, 4), (5, 6)]})
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
注意不要在.ipynb中运行。
|
|
173
|
+
|
|
174
|
+
👉 想查看完整Quick Start,请见[Quick Start](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/quick_start.md)
|
|
175
|
+
|
|
176
|
+
## 深入阅读(Further Reading)
|
|
177
|
+
|
|
178
|
+
(以下文档完善中)
|
|
179
|
+
|
|
180
|
+
你可以继续运行更多的测试代码,这里记录了各个测试文件与其中的测试函数说明:
|
|
181
|
+
|
|
182
|
+
[📄tests/README.md](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/tests/README.md)
|
|
183
|
+
|
|
184
|
+
若你想了解框架的整体结构与核心组件,下面的参考文档会对你有帮助:
|
|
185
|
+
|
|
186
|
+
- [🔧TaskManage/TaskStage概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_manage.md)
|
|
187
|
+
- [🌐TaskGrapg概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_graph.md)
|
|
188
|
+
- [📚Go Worker概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/go_worker.md)
|
|
189
|
+
|
|
190
|
+
推荐阅读顺序:
|
|
191
|
+
|
|
192
|
+
```mermaid
|
|
193
|
+
flowchart TD
|
|
194
|
+
classDef whiteNode fill:#ffffff,stroke:#000000,color:#000000;
|
|
195
|
+
|
|
196
|
+
TM[TaskManage] --> TG[TaskGraph]
|
|
197
|
+
TM --> TP[TaskProgress]
|
|
198
|
+
|
|
199
|
+
TG --> TQ[TaskQueue]
|
|
200
|
+
TG --> TN[TaskNodes]
|
|
201
|
+
TG --> TR[TaskReport]
|
|
202
|
+
TG --> TS[TaskStructure]
|
|
203
|
+
|
|
204
|
+
TR --> TW[TaskWeb]
|
|
205
|
+
TN --> GW[Go Worker]
|
|
206
|
+
|
|
207
|
+
class TM,TG,TP,TQ,TN,TR,TS,TW,GW whiteNode;
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
以下三篇可以作为补充阅读:
|
|
211
|
+
|
|
212
|
+
- [TaskTools](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_tools.md)
|
|
213
|
+
- [TaskTypes](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_types.md)
|
|
214
|
+
- [TaskLogging](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_logging.md)
|
|
215
|
+
|
|
216
|
+
如果你更喜欢通过完整案例理解框架的运行方式,可以参考这篇从零开始构建 TaskGraph 的教程:
|
|
217
|
+
|
|
218
|
+
[📘案例教程](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/tutorial.md)
|
|
219
|
+
|
|
220
|
+
## 环境要求(Requirements)
|
|
221
|
+
|
|
222
|
+
**CelestialFlow** 基于 Python 3.8+,并依赖以下核心组件。
|
|
223
|
+
请确保你的环境能够正常安装这些依赖(`pip install celestialflow` 会自动安装)。
|
|
224
|
+
|
|
225
|
+
| 依赖包 | 说明 |
|
|
226
|
+
| ---------------- | ---- |
|
|
227
|
+
| **Python ≥ 3.8** | 运行环境,建议使用 3.10 及以上版本 |
|
|
228
|
+
| **tqdm** | 控制台进度条显示,用于任务执行可视化 |
|
|
229
|
+
| **loguru** | 高性能日志系统,支持多进程安全输出 |
|
|
230
|
+
| **fastapi** | Web 服务接口框架(用于任务可视化与远程控制) |
|
|
231
|
+
| **uvicorn** | FastAPI 的高性能 ASGI 服务器 |
|
|
232
|
+
| **requests** | HTTP 客户端库,用于任务状态上报与远程调用 |
|
|
233
|
+
| **networkx** | 任务图(TaskGraph)结构与依赖分析 |
|
|
234
|
+
| **redis** | 可选组件,用于分布式任务通信(`TaskRedis*` 系列模块) |
|
|
235
|
+
| **jinja2** | FastAPI 模板引擎,用于 Web 可视化界面渲染 |
|
|
236
|
+
|
|
237
|
+
## 文件结构(File Structure)
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
📁 CelestialFlow (205MB 169KB 76B)
|
|
241
|
+
📁 experiments (14KB 536B)
|
|
242
|
+
🐍 benchmark_datastructures.py (5KB 796B)
|
|
243
|
+
🐍 benchmark_hash.py (1KB 284B)
|
|
244
|
+
🐍 benchmark_queue.py (5KB 185B)
|
|
245
|
+
🐍 benchmark_tqdm.py (1KB 160B)
|
|
246
|
+
🐍 experiment_tqdm.py (1KB 135B)
|
|
247
|
+
📁 go_worker (6MB 967KB 64B)
|
|
248
|
+
📁 worker (5KB 684B)
|
|
249
|
+
🌀 parser.go (394B)
|
|
250
|
+
🌀 processor.go (2KB 612B)
|
|
251
|
+
🌀 types.go (237B)
|
|
252
|
+
🌀 worker.go (2KB 465B)
|
|
253
|
+
❓ go.mod (258B)
|
|
254
|
+
❓ go.sum (591B)
|
|
255
|
+
❓ go_worker.exe (6MB 960KB)
|
|
256
|
+
🌀 main.go (579B)
|
|
257
|
+
📁 img (966KB 63B)
|
|
258
|
+
📷 logo.png (836KB 542B)
|
|
259
|
+
📷 web_display.png (129KB 545B)
|
|
260
|
+
📁 src (1MB 884KB 224B)
|
|
261
|
+
📁 celestialflow (1MB 869KB 480B)
|
|
262
|
+
📁 static (1MB 419KB 510B)
|
|
263
|
+
📁 css (32KB 568B)
|
|
264
|
+
🎨 base.css (6KB 155B)
|
|
265
|
+
🎨 dashboard.css (8KB 435B)
|
|
266
|
+
🎨 errors.css (5KB 168B)
|
|
267
|
+
🎨 inject.css (12KB 834B)
|
|
268
|
+
📁 js (34KB 868B)
|
|
269
|
+
📜 main.js (4KB 973B)
|
|
270
|
+
📜 task_errors.js (4KB 544B)
|
|
271
|
+
📜 task_injection.js (8KB 491B)
|
|
272
|
+
📜 task_statuses.js (8KB 63B)
|
|
273
|
+
📜 task_structure.js (7KB 143B)
|
|
274
|
+
📜 task_topology.js (261B)
|
|
275
|
+
📜 utils.js (1KB 441B)
|
|
276
|
+
❓ favicon.ico (1MB 352KB 98B)
|
|
277
|
+
📁 templates (12KB 973B)
|
|
278
|
+
🌐 index.html (12KB 973B)
|
|
279
|
+
📁 [1项排除的目录] (314KB 710B)
|
|
280
|
+
📝 README.md (13KB 131B)
|
|
281
|
+
🐍 task_graph.py (22KB 530B)
|
|
282
|
+
🐍 task_logging.py (6KB 291B)
|
|
283
|
+
🐍 task_manage.py (32KB 66B)
|
|
284
|
+
🐍 task_nodes.py (4KB 953B)
|
|
285
|
+
🐍 task_progress.py (1KB 477B)
|
|
286
|
+
🐍 task_queue.py (7KB 896B)
|
|
287
|
+
🐍 task_report.py (5KB 511B)
|
|
288
|
+
🐍 task_structure.py (6KB 93B)
|
|
289
|
+
🐍 task_tools.py (15KB 182B)
|
|
290
|
+
🐍 task_types.py (1KB 461B)
|
|
291
|
+
🐍 task_web.py (5KB 47B)
|
|
292
|
+
🐍 __init__.py (817B)
|
|
293
|
+
📁 celestialflow.egg-info (14KB 768B)
|
|
294
|
+
❓ PKG-INFO (13KB 363B)
|
|
295
|
+
📄 [5项排除的文件] (1KB 405B)
|
|
296
|
+
📁 tests (113KB 510B)
|
|
297
|
+
📁 [1项排除的目录] (81KB 604B)
|
|
298
|
+
📝 README.md (7KB 231B)
|
|
299
|
+
🐍 test_graph.py (5KB 83B)
|
|
300
|
+
🐍 test_manage.py (1KB 785B)
|
|
301
|
+
🐍 test_nodes.py (7KB 864B)
|
|
302
|
+
🐍 test_structure.py (9KB 1015B)
|
|
303
|
+
📁 [6项排除的目录] (195MB 276KB 932B)
|
|
304
|
+
❓ .gitignore (264B)
|
|
305
|
+
❓ LICENSE (1KB 65B)
|
|
306
|
+
❓ Makefile (501B)
|
|
307
|
+
❓ pyproject.toml (1KB 223B)
|
|
308
|
+
⚙️ pytest.ini (254B)
|
|
309
|
+
📝 README.md (15KB 536B)
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
(该视图由我的另一个项目[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)中inst_file生成。)
|
|
313
|
+
|
|
314
|
+
## 更新日志(Change Log)
|
|
315
|
+
|
|
316
|
+
- [2021] 建立一个支持多线程与单线程处理函数的类
|
|
317
|
+
- [2023] 在GPT4帮助下添加多进程与携程运行模式
|
|
318
|
+
- [5/9/2024] 将原有的处理类抽象为节点, 添加TaskChain类, 可以线性连接多个节点, 并设定节点在Chain中的运行模式, 支持serial和process两种, 后者Chain所有节点同时运行
|
|
319
|
+
- [12/12/2024-12/16/2024] 在原有链式结构基础上允许节点有复数下级节点, 实现Tree结构; 将原有TaskChain改名为TaskTree
|
|
320
|
+
- [3/16/2025] 支持Web端任务完成情况可视化
|
|
321
|
+
- [6/9/2025] 支持节点拥有复数上级节点, 脱离纯Tree结构, 为之后循环图做准备
|
|
322
|
+
- [6/11/2025] 自[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)项目instances.inst_task迁入
|
|
323
|
+
- [6/12/2025] 支持循环图, 下级节点可指向上级节点
|
|
324
|
+
- [6/13/2025] 支持loop结构, 即节点可指向自己
|
|
325
|
+
- [6/14/2025] 支持forest结构, 即可有多个根节点
|
|
326
|
+
- [6/16/2025] 多轮评测后, 当前框架已支持完整有向图结构, 故将TaskTree改名为TaskGraph
|
|
327
|
+
|
|
328
|
+
## Star 历史趋势(Star History)
|
|
329
|
+
|
|
330
|
+
如果对项目感兴趣的话,还请star。
|
|
331
|
+
|
|
332
|
+
[](https://star-history.com/#Mr-xiaotian/CelestialFlow&Date)
|
|
333
|
+
|
|
334
|
+
## 许可(License)
|
|
335
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
336
|
+
|
|
337
|
+
## 作者(Author)
|
|
338
|
+
Author: Mr-xiaotian
|
|
339
|
+
Email: mingxiaomingtian@gmail.com
|
|
340
|
+
Project Link: [https://github.com/Mr-xiaotian/CelestialFlow](https://github.com/Mr-xiaotian/CelestialFlow)
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
# CelestialFlow ——一个轻量级、可并行、基于图结构的 Python 任务调度框架
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/Mr-xiaotian/CelestialFlow/main/img/logo.png" width="1080" alt="CelestialFlow Logo">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://pypi.org/project/celestialflow/"><img src="https://badge.fury.io/py/celestialflow.svg"></a>
|
|
9
|
+
<a href="https://pepy.tech/projects/celestialflow"><img src="https://static.pepy.tech/personalized-badge/celestialflow?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads"></a>
|
|
10
|
+
<a href="https://pypi.org/project/celestialflow/"><img src="https://img.shields.io/pypi/l/celestialflow.svg"></a>
|
|
11
|
+
<a href="https://pypi.org/project/celestialflow/"><img src="https://img.shields.io/pypi/pyversions/celestialflow.svg"></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
**CelestialFlow** 是一个轻量级但功能完全体的任务流框架,适合需要“灵活拓扑 + 多执行模式 + 可视化监控”的中/大型 Python 任务系统。
|
|
15
|
+
|
|
16
|
+
- 相比 Airflow/Dagster 更轻、更快开始
|
|
17
|
+
- 相比 multiprocessing/threading 更结构化,可直接表达 loop / complete graph 等复杂依赖
|
|
18
|
+
|
|
19
|
+
框架的基本单元为 **TaskStage**(由 `TaskManager` 派生),每个 stage 内部绑定一个独立的执行函数,并支持四种运行模式:
|
|
20
|
+
|
|
21
|
+
* **线性(serial)**
|
|
22
|
+
* **多线程(thread)**
|
|
23
|
+
* **多进程(process)**
|
|
24
|
+
* **协程(async)**
|
|
25
|
+
|
|
26
|
+
每个 stage 均可独立运行,也可作为节点互相连接,形成具有上游与下游依赖关系的任务图(**TaskGraph**)。下游 stage 会自动接收上游执行完成的结果作为输入,从而实现数据的流动与传递。
|
|
27
|
+
|
|
28
|
+
在图级别上,TaskGraph 支持两种布局模式:
|
|
29
|
+
|
|
30
|
+
* **线性执行(serial layout)**:前一节点执行完毕后再启动下一节点(下游节点可提前接收任务但不会立即执行)。
|
|
31
|
+
* **并行执行(process layout)**:所有节点同时启动运行,由队列自动协调任务传递与依赖顺序。
|
|
32
|
+
|
|
33
|
+
TaskGraph 能构建完整的 **有向图结构(Directed Graph)**,不仅支持传统的有向无环图(DAG),也能灵活表达 **环形(loop)** 与 **复杂交叉** 的任务依赖。
|
|
34
|
+
|
|
35
|
+
在此基础上项目支持 Web 可视化与通过 Redis 外接go代码,弥补 Python 在cpu密集任务上速度过慢的问题。
|
|
36
|
+
|
|
37
|
+
## 项目结构(Project Structure)
|
|
38
|
+
|
|
39
|
+
```mermaid
|
|
40
|
+
flowchart LR
|
|
41
|
+
|
|
42
|
+
%% ===== TaskGraph =====
|
|
43
|
+
subgraph TG[TaskGraph]
|
|
44
|
+
direction LR
|
|
45
|
+
|
|
46
|
+
S1[TaskStage A]
|
|
47
|
+
S2[TaskStage B]
|
|
48
|
+
S3[TaskStage C]
|
|
49
|
+
S4[TaskStage D]
|
|
50
|
+
|
|
51
|
+
T1[Last Stage]
|
|
52
|
+
T2[Next Stage]
|
|
53
|
+
|
|
54
|
+
TS[[TaskSplitter]]
|
|
55
|
+
TRSI1[/TaskRedisSink/]
|
|
56
|
+
TRSI2[/TaskRedisSink/]
|
|
57
|
+
TRSO[/TaskRedisSource/]
|
|
58
|
+
TRA[/TaskRedisAck/]
|
|
59
|
+
|
|
60
|
+
RE1[(Redis)]
|
|
61
|
+
RE2[(Redis)]
|
|
62
|
+
G1((GoWorker))
|
|
63
|
+
G2((GoWorker))
|
|
64
|
+
|
|
65
|
+
S1 --> S2 --> S3 --> S1
|
|
66
|
+
S1 --> S4
|
|
67
|
+
|
|
68
|
+
T1 -->|1 task| TS
|
|
69
|
+
TS -->|N task| T2
|
|
70
|
+
|
|
71
|
+
TRSI1 -.-> RE1 -.-> TRSO
|
|
72
|
+
TRSI2 -.->|task| RE2 -.->|task| G1
|
|
73
|
+
G2 -.->|result| RE2 -.->|result| TRA
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
%% 美化 TaskGraph 外框
|
|
78
|
+
style TG fill:#e8f2ff,stroke:#6b93d6,stroke-width:2px,color:#0b1e3f,rx:10px,ry:10px
|
|
79
|
+
|
|
80
|
+
%% 统一美化格式
|
|
81
|
+
classDef blueNode fill:#ffffff,stroke:#6b93d6,rx:6px,ry:6px;
|
|
82
|
+
|
|
83
|
+
%% 美化 TaskStages
|
|
84
|
+
class S1,S2,S3,S4 blueNode;
|
|
85
|
+
class T1,T2 blueNode;
|
|
86
|
+
|
|
87
|
+
%% 美化 特殊Stage
|
|
88
|
+
class TS,TRA,TRSI1,TRSI2,TRSO blueNode;
|
|
89
|
+
|
|
90
|
+
%% 美化 外部结构
|
|
91
|
+
class RE1,RE2,G1,G2 blueNode;
|
|
92
|
+
|
|
93
|
+
%% ===== WebUI =====
|
|
94
|
+
subgraph W[WebUI]
|
|
95
|
+
JS
|
|
96
|
+
HTML
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
style W fill:#ffeaf0,stroke:#d66b8c,stroke-width:2px,rx:10px,ry:10px
|
|
100
|
+
style JS fill:#ffffff,stroke:#d66b8c,rx:5px,ry:5px
|
|
101
|
+
style HTML fill:#ffffff,stroke:#d66b8c,rx:5px,ry:5px
|
|
102
|
+
|
|
103
|
+
R[TaskWeb]
|
|
104
|
+
style R fill:#f0e9ff,stroke:#8a6bc9,stroke-width:2px,rx:8px,ry:8px
|
|
105
|
+
|
|
106
|
+
%% ===== Links =====
|
|
107
|
+
TG --> R
|
|
108
|
+
R --> TG
|
|
109
|
+
R --> W
|
|
110
|
+
W --> R
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## 快速开始(Quick Start)
|
|
115
|
+
|
|
116
|
+
安装 CelestialFlow:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
pip install celestialflow
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
一个简单的可运行代码:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from celestialflow import TaskManager, TaskGraph
|
|
126
|
+
|
|
127
|
+
def add(x, y):
|
|
128
|
+
return x + y
|
|
129
|
+
|
|
130
|
+
def square(x):
|
|
131
|
+
return x ** 2
|
|
132
|
+
|
|
133
|
+
if __name__ == "__main__":
|
|
134
|
+
# 定义两个任务节点
|
|
135
|
+
stage1 = TaskManager(add, execution_mode="thread", unpack_task_args=True)
|
|
136
|
+
stage2 = TaskManager(square, execution_mode="thread")
|
|
137
|
+
|
|
138
|
+
# 构建任务图结构
|
|
139
|
+
stage1.set_graph_context([stage2], stage_mode="process", stage_name="Adder")
|
|
140
|
+
stage2.set_graph_context([], stage_mode="process", stage_name="Squarer")
|
|
141
|
+
graph = TaskGraph([stage1])
|
|
142
|
+
|
|
143
|
+
# 初始化任务并启动
|
|
144
|
+
graph.start_graph({stage1.get_stage_tag(): [(1, 2), (3, 4), (5, 6)]})
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
注意不要在.ipynb中运行。
|
|
148
|
+
|
|
149
|
+
👉 想查看完整Quick Start,请见[Quick Start](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/quick_start.md)
|
|
150
|
+
|
|
151
|
+
## 深入阅读(Further Reading)
|
|
152
|
+
|
|
153
|
+
(以下文档完善中)
|
|
154
|
+
|
|
155
|
+
你可以继续运行更多的测试代码,这里记录了各个测试文件与其中的测试函数说明:
|
|
156
|
+
|
|
157
|
+
[📄tests/README.md](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/tests/README.md)
|
|
158
|
+
|
|
159
|
+
若你想了解框架的整体结构与核心组件,下面的参考文档会对你有帮助:
|
|
160
|
+
|
|
161
|
+
- [🔧TaskManage/TaskStage概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_manage.md)
|
|
162
|
+
- [🌐TaskGrapg概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_graph.md)
|
|
163
|
+
- [📚Go Worker概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/go_worker.md)
|
|
164
|
+
|
|
165
|
+
推荐阅读顺序:
|
|
166
|
+
|
|
167
|
+
```mermaid
|
|
168
|
+
flowchart TD
|
|
169
|
+
classDef whiteNode fill:#ffffff,stroke:#000000,color:#000000;
|
|
170
|
+
|
|
171
|
+
TM[TaskManage] --> TG[TaskGraph]
|
|
172
|
+
TM --> TP[TaskProgress]
|
|
173
|
+
|
|
174
|
+
TG --> TQ[TaskQueue]
|
|
175
|
+
TG --> TN[TaskNodes]
|
|
176
|
+
TG --> TR[TaskReport]
|
|
177
|
+
TG --> TS[TaskStructure]
|
|
178
|
+
|
|
179
|
+
TR --> TW[TaskWeb]
|
|
180
|
+
TN --> GW[Go Worker]
|
|
181
|
+
|
|
182
|
+
class TM,TG,TP,TQ,TN,TR,TS,TW,GW whiteNode;
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
以下三篇可以作为补充阅读:
|
|
186
|
+
|
|
187
|
+
- [TaskTools](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_tools.md)
|
|
188
|
+
- [TaskTypes](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_types.md)
|
|
189
|
+
- [TaskLogging](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_logging.md)
|
|
190
|
+
|
|
191
|
+
如果你更喜欢通过完整案例理解框架的运行方式,可以参考这篇从零开始构建 TaskGraph 的教程:
|
|
192
|
+
|
|
193
|
+
[📘案例教程](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/tutorial.md)
|
|
194
|
+
|
|
195
|
+
## 环境要求(Requirements)
|
|
196
|
+
|
|
197
|
+
**CelestialFlow** 基于 Python 3.8+,并依赖以下核心组件。
|
|
198
|
+
请确保你的环境能够正常安装这些依赖(`pip install celestialflow` 会自动安装)。
|
|
199
|
+
|
|
200
|
+
| 依赖包 | 说明 |
|
|
201
|
+
| ---------------- | ---- |
|
|
202
|
+
| **Python ≥ 3.8** | 运行环境,建议使用 3.10 及以上版本 |
|
|
203
|
+
| **tqdm** | 控制台进度条显示,用于任务执行可视化 |
|
|
204
|
+
| **loguru** | 高性能日志系统,支持多进程安全输出 |
|
|
205
|
+
| **fastapi** | Web 服务接口框架(用于任务可视化与远程控制) |
|
|
206
|
+
| **uvicorn** | FastAPI 的高性能 ASGI 服务器 |
|
|
207
|
+
| **requests** | HTTP 客户端库,用于任务状态上报与远程调用 |
|
|
208
|
+
| **networkx** | 任务图(TaskGraph)结构与依赖分析 |
|
|
209
|
+
| **redis** | 可选组件,用于分布式任务通信(`TaskRedis*` 系列模块) |
|
|
210
|
+
| **jinja2** | FastAPI 模板引擎,用于 Web 可视化界面渲染 |
|
|
211
|
+
|
|
212
|
+
## 文件结构(File Structure)
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
📁 CelestialFlow (205MB 169KB 76B)
|
|
216
|
+
📁 experiments (14KB 536B)
|
|
217
|
+
🐍 benchmark_datastructures.py (5KB 796B)
|
|
218
|
+
🐍 benchmark_hash.py (1KB 284B)
|
|
219
|
+
🐍 benchmark_queue.py (5KB 185B)
|
|
220
|
+
🐍 benchmark_tqdm.py (1KB 160B)
|
|
221
|
+
🐍 experiment_tqdm.py (1KB 135B)
|
|
222
|
+
📁 go_worker (6MB 967KB 64B)
|
|
223
|
+
📁 worker (5KB 684B)
|
|
224
|
+
🌀 parser.go (394B)
|
|
225
|
+
🌀 processor.go (2KB 612B)
|
|
226
|
+
🌀 types.go (237B)
|
|
227
|
+
🌀 worker.go (2KB 465B)
|
|
228
|
+
❓ go.mod (258B)
|
|
229
|
+
❓ go.sum (591B)
|
|
230
|
+
❓ go_worker.exe (6MB 960KB)
|
|
231
|
+
🌀 main.go (579B)
|
|
232
|
+
📁 img (966KB 63B)
|
|
233
|
+
📷 logo.png (836KB 542B)
|
|
234
|
+
📷 web_display.png (129KB 545B)
|
|
235
|
+
📁 src (1MB 884KB 224B)
|
|
236
|
+
📁 celestialflow (1MB 869KB 480B)
|
|
237
|
+
📁 static (1MB 419KB 510B)
|
|
238
|
+
📁 css (32KB 568B)
|
|
239
|
+
🎨 base.css (6KB 155B)
|
|
240
|
+
🎨 dashboard.css (8KB 435B)
|
|
241
|
+
🎨 errors.css (5KB 168B)
|
|
242
|
+
🎨 inject.css (12KB 834B)
|
|
243
|
+
📁 js (34KB 868B)
|
|
244
|
+
📜 main.js (4KB 973B)
|
|
245
|
+
📜 task_errors.js (4KB 544B)
|
|
246
|
+
📜 task_injection.js (8KB 491B)
|
|
247
|
+
📜 task_statuses.js (8KB 63B)
|
|
248
|
+
📜 task_structure.js (7KB 143B)
|
|
249
|
+
📜 task_topology.js (261B)
|
|
250
|
+
📜 utils.js (1KB 441B)
|
|
251
|
+
❓ favicon.ico (1MB 352KB 98B)
|
|
252
|
+
📁 templates (12KB 973B)
|
|
253
|
+
🌐 index.html (12KB 973B)
|
|
254
|
+
📁 [1项排除的目录] (314KB 710B)
|
|
255
|
+
📝 README.md (13KB 131B)
|
|
256
|
+
🐍 task_graph.py (22KB 530B)
|
|
257
|
+
🐍 task_logging.py (6KB 291B)
|
|
258
|
+
🐍 task_manage.py (32KB 66B)
|
|
259
|
+
🐍 task_nodes.py (4KB 953B)
|
|
260
|
+
🐍 task_progress.py (1KB 477B)
|
|
261
|
+
🐍 task_queue.py (7KB 896B)
|
|
262
|
+
🐍 task_report.py (5KB 511B)
|
|
263
|
+
🐍 task_structure.py (6KB 93B)
|
|
264
|
+
🐍 task_tools.py (15KB 182B)
|
|
265
|
+
🐍 task_types.py (1KB 461B)
|
|
266
|
+
🐍 task_web.py (5KB 47B)
|
|
267
|
+
🐍 __init__.py (817B)
|
|
268
|
+
📁 celestialflow.egg-info (14KB 768B)
|
|
269
|
+
❓ PKG-INFO (13KB 363B)
|
|
270
|
+
📄 [5项排除的文件] (1KB 405B)
|
|
271
|
+
📁 tests (113KB 510B)
|
|
272
|
+
📁 [1项排除的目录] (81KB 604B)
|
|
273
|
+
📝 README.md (7KB 231B)
|
|
274
|
+
🐍 test_graph.py (5KB 83B)
|
|
275
|
+
🐍 test_manage.py (1KB 785B)
|
|
276
|
+
🐍 test_nodes.py (7KB 864B)
|
|
277
|
+
🐍 test_structure.py (9KB 1015B)
|
|
278
|
+
📁 [6项排除的目录] (195MB 276KB 932B)
|
|
279
|
+
❓ .gitignore (264B)
|
|
280
|
+
❓ LICENSE (1KB 65B)
|
|
281
|
+
❓ Makefile (501B)
|
|
282
|
+
❓ pyproject.toml (1KB 223B)
|
|
283
|
+
⚙️ pytest.ini (254B)
|
|
284
|
+
📝 README.md (15KB 536B)
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
(该视图由我的另一个项目[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)中inst_file生成。)
|
|
288
|
+
|
|
289
|
+
## 更新日志(Change Log)
|
|
290
|
+
|
|
291
|
+
- [2021] 建立一个支持多线程与单线程处理函数的类
|
|
292
|
+
- [2023] 在GPT4帮助下添加多进程与携程运行模式
|
|
293
|
+
- [5/9/2024] 将原有的处理类抽象为节点, 添加TaskChain类, 可以线性连接多个节点, 并设定节点在Chain中的运行模式, 支持serial和process两种, 后者Chain所有节点同时运行
|
|
294
|
+
- [12/12/2024-12/16/2024] 在原有链式结构基础上允许节点有复数下级节点, 实现Tree结构; 将原有TaskChain改名为TaskTree
|
|
295
|
+
- [3/16/2025] 支持Web端任务完成情况可视化
|
|
296
|
+
- [6/9/2025] 支持节点拥有复数上级节点, 脱离纯Tree结构, 为之后循环图做准备
|
|
297
|
+
- [6/11/2025] 自[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)项目instances.inst_task迁入
|
|
298
|
+
- [6/12/2025] 支持循环图, 下级节点可指向上级节点
|
|
299
|
+
- [6/13/2025] 支持loop结构, 即节点可指向自己
|
|
300
|
+
- [6/14/2025] 支持forest结构, 即可有多个根节点
|
|
301
|
+
- [6/16/2025] 多轮评测后, 当前框架已支持完整有向图结构, 故将TaskTree改名为TaskGraph
|
|
302
|
+
|
|
303
|
+
## Star 历史趋势(Star History)
|
|
304
|
+
|
|
305
|
+
如果对项目感兴趣的话,还请star。
|
|
306
|
+
|
|
307
|
+
[](https://star-history.com/#Mr-xiaotian/CelestialFlow&Date)
|
|
308
|
+
|
|
309
|
+
## 许可(License)
|
|
310
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
311
|
+
|
|
312
|
+
## 作者(Author)
|
|
313
|
+
Author: Mr-xiaotian
|
|
314
|
+
Email: mingxiaomingtian@gmail.com
|
|
315
|
+
Project Link: [https://github.com/Mr-xiaotian/CelestialFlow](https://github.com/Mr-xiaotian/CelestialFlow)
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
from .task_graph import TaskGraph
|
|
2
2
|
from .task_manage import TaskManager
|
|
3
|
-
from .task_nodes import
|
|
3
|
+
from .task_nodes import (
|
|
4
|
+
TaskSplitter,
|
|
5
|
+
TaskRedisSink,
|
|
6
|
+
TaskRedisSource,
|
|
7
|
+
TaskRedisAck,
|
|
8
|
+
)
|
|
4
9
|
from .task_structure import (
|
|
5
10
|
TaskChain,
|
|
6
11
|
TaskLoop,
|
|
@@ -28,7 +33,9 @@ __all__ = [
|
|
|
28
33
|
"TaskGrid",
|
|
29
34
|
"TaskManager",
|
|
30
35
|
"TaskSplitter",
|
|
31
|
-
"
|
|
36
|
+
"TaskRedisSink",
|
|
37
|
+
"TaskRedisSource",
|
|
38
|
+
"TaskRedisAck",
|
|
32
39
|
"TerminationSignal",
|
|
33
40
|
"TaskWebServer",
|
|
34
41
|
"load_task_by_stage",
|