Skip to content

Commit 021022b

Browse files
committed
Merge branch 'main' of github.com:xinetzone/tao
2 parents 7ad8ea3 + 48d204d commit 021022b

File tree

10 files changed

+433
-49
lines changed

10 files changed

+433
-49
lines changed

doc/InsightHub/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
pygallery <https://daobook.github.io/pygallery>
55
Matplotlib/index
66
maple-mono/index
7+
zeromq/index
78
chaos/index
89
```

doc/InsightHub/zeromq/basics.ipynb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "85f7e0dd",
6+
"metadata": {},
7+
"source": [
8+
"# ZeroMQ 基础"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "397f405e",
14+
"metadata": {},
15+
"source": [
16+
"如何解释 ZeroMQ?有些人从它所做的一切美妙的事情开始说起。它是强化版的套接字。它就像带路由的邮箱。它非常快!其他人则试图分享他们顿悟的时刻,那种 zap-pow-kaboom 般顿悟的范式转换时刻,当一切变得显而易见时。事情变得简单起来。复杂性消失了。它开阔了思维。还有些人通过比较来解释。它更小、更简单,但看起来依然熟悉。"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"id": "8c881bb5",
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"import anywidget\n",
27+
"import traitlets\n",
28+
"\n",
29+
"class CounterWidget(anywidget.AnyWidget):\n",
30+
" _esm = \"\"\"\n",
31+
" function render({ model, el }) {\n",
32+
" let button = document.createElement(\"button\");\n",
33+
" button.innerHTML = `count is ${model.get(\"value\")}`;\n",
34+
" button.addEventListener(\"click\", () => {\n",
35+
" model.set(\"value\", model.get(\"value\") + 1);\n",
36+
" model.save_changes();\n",
37+
" });\n",
38+
" model.on(\"change:value\", () => {\n",
39+
" button.innerHTML = `count is ${model.get(\"value\")}`;\n",
40+
" });\n",
41+
" el.classList.add(\"counter-widget\");\n",
42+
" el.appendChild(button);\n",
43+
" }\n",
44+
" export default { render };\n",
45+
" \"\"\"\n",
46+
" _css = \"\"\"\n",
47+
" .counter-widget button { color: white; font-size: 1.75rem; background-color: #ea580c; padding: 0.5rem 1rem; border: none; border-radius: 0.25rem; }\n",
48+
" .counter-widget button:hover { background-color: #9a3412; }\n",
49+
" \"\"\"\n",
50+
" value = traitlets.Int(0).tag(sync=True)\n",
51+
"\n",
52+
"w = CounterWidget(value=42)\n",
53+
"w"
54+
]
55+
}
56+
],
57+
"metadata": {
58+
"kernelspec": {
59+
"display_name": "py313",
60+
"language": "python",
61+
"name": "python3"
62+
},
63+
"language_info": {
64+
"codemirror_mode": {
65+
"name": "ipython",
66+
"version": 3
67+
},
68+
"file_extension": ".py",
69+
"mimetype": "text/x-python",
70+
"name": "python",
71+
"nbconvert_exporter": "python",
72+
"pygments_lexer": "ipython3",
73+
"version": "3.13.5"
74+
}
75+
},
76+
"nbformat": 4,
77+
"nbformat_minor": 5
78+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "b89d17d2",
6+
"metadata": {},
7+
"source": [
8+
"# 开始使用 ZeroMQ"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "108eede3",
14+
"metadata": {},
15+
"source": [
16+
"ZeroMQ(也拼写为 ØMQ、0MQ 或 ZMQ)是高性能异步消息传递库,旨在用于分布式或并发应用程序。它提供了一个消息队列,但与面向消息的中间件不同,ZeroMQ 系统可以在没有专用消息代理的情况下运行。\n",
17+
"\n",
18+
"ZeroMQ 支持通过各种传输(TCP、进程内、进程间、multicast、WebSocket 等)的常见消息传递模式(发布/订阅、请求/回复、客户端/服务器等),使进程间消息传递像线程间消息传递一样简单。这使您的代码保持清晰、模块化且极其易于扩展。\n",
19+
"\n",
20+
"ZeroMQ 是由庞大的贡献者社区开发的。许多流行的编程语言都有第三方绑定,C# 和 Java 也有本机端口。\n",
21+
"\n",
22+
"```{admonition} ZeroMQ 中的零\n",
23+
"ZeroMQ 的理念从零开始。零表示零代理(ZeroMQ 是无代理)、零延迟、零成本(免费)和零管理。\n",
24+
"\n",
25+
"更一般地说,“零”是指渗透到项目中的极简主义文化。通过消除复杂性而不是通过公开新功能来增加功能。\n",
26+
"```"
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"id": "b22c6bf4",
32+
"metadata": {},
33+
"source": [
34+
"[指南](http://zguide.zeromq.org/page:all)解释了如何使用 ØMQ,涵盖了基础、中级和高级使用,包括 60+ 图表和 750 个示例,包括 28 种语言。\n"
35+
]
36+
},
37+
{
38+
"cell_type": "markdown",
39+
"id": "b07876d3",
40+
"metadata": {},
41+
"source": [
42+
"```{admonition} 用一百个字描述 ZeroMQ\n",
43+
"ZeroMQ(也称为ØMQ、0MQ 或 zmq)看起来像是可嵌入的网络库,但实际上是并发框架。它为您提供可以在进程内、进程间、TCP 和多播等不同传输方式上携带原子消息的套接字。您可以使用类似 fan-out、pub-sub、任务分配和请求-回复的模式将套接字 N 对 N 地连接起来。它足够快,可以成为集群产品的架构。其异步 I/O 模型让您能够构建可扩展的多核应用程序,这些应用程序作为异步消息处理任务。它拥有多种语言 API,并在大多数操作系统上运行。ZeroMQ 来自 [iMatix](http://www.imatix.com/),是 LGPLv3 开源项目。\n",
44+
"```"
45+
]
46+
},
47+
{
48+
"cell_type": "markdown",
49+
"id": "48093bb8",
50+
"metadata": {},
51+
"source": [
52+
"## 第一个 Python 例子\n",
53+
"\n",
54+
"安装\n",
55+
"```bash\n",
56+
"pip install pyzmq\n",
57+
"```\n"
58+
]
59+
},
60+
{
61+
"cell_type": "markdown",
62+
"id": "bc385bff",
63+
"metadata": {},
64+
"source": [
65+
"```python\n",
66+
"#\n",
67+
"# Hello World server in Python\n",
68+
"# Binds REP socket to tcp://*:5555\n",
69+
"# Expects b\"Hello\" from client, replies with b\"World\"\n",
70+
"#\n",
71+
"\n",
72+
"import time\n",
73+
"import zmq\n",
74+
"\n",
75+
"context = zmq.Context()\n",
76+
"socket = context.socket(zmq.REP)\n",
77+
"socket.bind(\"tcp://*:5555\")\n",
78+
"\n",
79+
"while True:\n",
80+
" # Wait for next request from client\n",
81+
" message = socket.recv()\n",
82+
" print(f\"Received request: {message}\")\n",
83+
"\n",
84+
" # Do some 'work'\n",
85+
" time.sleep(1)\n",
86+
"\n",
87+
" # Send reply back to client\n",
88+
" socket.send(b\"World\")\n",
89+
"````"
90+
]
91+
},
92+
{
93+
"cell_type": "markdown",
94+
"id": "30ed2018",
95+
"metadata": {},
96+
"source": [
97+
"服务器创建 response 类型的套接字,将其绑定到端口 5555,然后等待消息。您还可以看到配置为零,只是在发送字符串。\n",
98+
"\n",
99+
"```python\n",
100+
"#\n",
101+
"# Hello World client in Python\n",
102+
"# Connects REQ socket to tcp://localhost:5555\n",
103+
"# Sends \"Hello\" to server, expects \"World\" back\n",
104+
"#\n",
105+
"\n",
106+
"import zmq\n",
107+
"\n",
108+
"context = zmq.Context()\n",
109+
"\n",
110+
"# Socket to talk to server\n",
111+
"print(\"Connecting to hello world server…\")\n",
112+
"socket = context.socket(zmq.REQ)\n",
113+
"socket.connect(\"tcp://localhost:5555\")\n",
114+
"\n",
115+
"# Do 10 requests, waiting each time for a response\n",
116+
"for request in range(10):\n",
117+
" print(f\"Sending request {request} …\")\n",
118+
" socket.send(b\"Hello\")\n",
119+
"\n",
120+
" # Get the reply.\n",
121+
" message = socket.recv()\n",
122+
" print(f\"Received reply {request} [ {message} ]\")\n",
123+
"```"
124+
]
125+
},
126+
{
127+
"cell_type": "markdown",
128+
"id": "36863dfe",
129+
"metadata": {},
130+
"source": [
131+
"客户端创建 request 类型的套接字,连接并开始发送消息。\n",
132+
"\n",
133+
"默认情况下, 发送和接收方法都处于阻塞状态。对于接收很简单:如果没有消息,该方法将阻塞。对于发送,它更复杂,取决于 socket 类型。对于请求套接字,如果达到高水位线或未连接对等方,则该方法将阻塞。"
134+
]
135+
}
136+
],
137+
"metadata": {
138+
"language_info": {
139+
"name": "python"
140+
}
141+
},
142+
"nbformat": 4,
143+
"nbformat_minor": 5
144+
}

doc/InsightHub/zeromq/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# ZeroMQ
2+
3+
参考:[ZeroMQ 官方文档](https://zeromq.org/)
4+
5+
```{toctree}
6+
get-started
7+
basics
8+
```

doc/conf.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def get_project_root():
5757
"sphinx_comments", # 添加评论和注释功能
5858
"sphinx_tippy", # 展示丰富的悬停提示
5959
"sphinx_thebe", # 配置交互式启动按钮
60+
"nbsphinx", # 支持Jupyter组件
6061

6162
# API文档与站点管理
6263
"autoapi.extension", # 自动生成API文档
@@ -70,6 +71,7 @@ def get_project_root():
7071
"_build", # 构建输出目录
7172
"Thumbs.db", # 缩略图数据库
7273
".DS_Store", # macOS 系统文件
74+
"**.ipynb_checkpoints", # Jupyter 笔记本检查点目录
7375
]
7476

7577
# 静态资源目录,用于存放CSS、JavaScript、图片等
@@ -208,6 +210,27 @@ def get_project_root():
208210
"autoapi.python_import_resolution",
209211
"autoapi.not_readable",
210212
]
213+
nb_execution_mode = "cache"
214+
# nb_ipywidgets_js = {
215+
# # "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js": {
216+
# # "integrity": "sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=",
217+
# # "crossorigin": "anonymous",
218+
# # },
219+
# "https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@*/dist/embed-amd.js": {
220+
# "data-jupyter-widgets-cdn": "https://cdn.jsdelivr.net/npm/",
221+
# "crossorigin": "anonymous",
222+
# },
223+
# "https://cdn.jsdelivr.net/npm/anywidget@*/dist/index.js": {
224+
# "integrity": "sha256-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
225+
# "crossorigin": "anonymous",
226+
# }
227+
# }
228+
# html_js_files = [
229+
# # "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js",
230+
# "https://cdn.jsdelivr.net/npm/anywidget@*/dist/index.js"
231+
# ]
232+
nb_execution_allow_errors = True
233+
nb_execution_excludepatterns = ["InsightHub/maple-mono/**"]
211234

212235
# 数字编号配置
213236
numfig = True
@@ -226,14 +249,14 @@ def get_project_root():
226249
"substitution",
227250
]
228251

229-
# === LaTeX 字体配置 ===
230-
# 确保LaTeX能正确显示中文和特殊符号
231-
latex_engine = 'xelatex' # 使用xelatex引擎支持UTF-8
232-
latex_elements = {
233-
'preamble': r"""
234-
\usepackage{xeCJK}
235-
\setCJKmainfont{Maple Mono NF CN}
236-
\setCJKsansfont{WenQuanYi Micro Hei}
237-
\setCJKmonofont{Maple Mono NF CN}
238-
"""
239-
}
252+
# # === LaTeX 字体配置 ===
253+
# # 确保LaTeX能正确显示中文和特殊符号
254+
# latex_engine = 'xelatex' # 使用xelatex引擎支持UTF-8
255+
# latex_elements = {
256+
# 'preamble': r"""
257+
# \usepackage{xeCJK}
258+
# \setCJKmainfont{Maple Mono NF CN}
259+
# \setCJKsansfont{WenQuanYi Micro Hei}
260+
# \setCJKmonofont{Maple Mono NF CN}
261+
# """
262+
# }

doc/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ readme
77
configs/index
88
InsightHub/index
99
notebook/index
10+
test-anywidget
1011
```
1112

1213
# 索引和表格
1314

1415
* {ref}`genindex`
1516
* {ref}`modindex`
16-
* {ref}`search`
17+
* {ref}`search`

0 commit comments

Comments
 (0)