Skip to content

Commit c77ea44

Browse files
📝 Update Python documentation with new content and structure
- Removed outdated sections and streamlined the content for clarity. - Added comprehensive guidance on managing Python environments and dependencies. - Introduced a new section on using third-party libraries, including installation and usage examples. - Enhanced the OpenCV documentation with practical examples and explanations. - Updated the library management section to include a detailed overview of a library system implementation. - Improved overall organization and readability of the Python documentation.
1 parent a5fbf24 commit c77ea44

File tree

9 files changed

+1765
-1739
lines changed

9 files changed

+1765
-1739
lines changed

docs/docs/机器学习/index.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,4 @@ title: 🚧机器学习
55

66
机器学习是当前发展最热门的方向之一,可以称之为计算机科学的明珠。
77

8-
我们可能会需要多个测试环境(例如:python3.9)去复现别人论文的代码,另一方面我们又需要一个最新的python去开发新的代码。
9-
10-
这就导致了一个问题,如何管理这些依赖,如何保证不同的模块库之间的兼容性,如何保证不同的模块库之间的可复用性。
11-
12-
常见的主流方案如下,可以按需选择:
13-
14-
| 工具 | 优点 | 缺点 | 适用场景 |
15-
|---------|------------------------------------------------------------|------------------------------------------------|------------------------------|
16-
| `venv` | 轻量级,不需要额外安装复杂的工具。 | 不能管理非Python的依赖,例如cuda版本。 | 传统的机器学习 |
17-
| `conda` | 功能强大,可以管理外部依赖。 | 体积大。迁移不方便。 | 深度学习 |
18-
| `docker`| 可以创建一个隔离的环境,并且可以方便的进行迁移。 | 需要学习和理解Docker的概念。 | 需要迁移的环境 |
19-
20-
这里我建议先使用传统的单环境开发,后续需要迁移环境时,再使用`conda`或者`docker`
21-
228
<DocCardList />

docs/docs/逆向测试/接口测试.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ aiohttp 模块:支持 HTTP2.0 仅异步
2525

2626
httpx 模块:支持 HTTP1.1/2.0 同步异步,双卡双待,是直接发起请求的模块中最全能的模块。
2727

28+
locust 模块:大规模的并发测试,可以实时查看吞吐量、响应时间和错误和/或导出以供以后分析。
29+
2830
### requests
2931

3032
requests 是基于 urllib3 开发的一个优雅而简单的 PythonHTTP 库,为人类构建。
@@ -213,3 +215,39 @@ with tempfile.NamedTemporaryFile() as download_file:
213215
download_file.write(chunk)
214216
progress.update(download_task, completed=response.num_bytes_downloaded)
215217
```
218+
219+
### locust
220+
221+
locust 需要创建一个`locustfile.py`的文件,他只是一个普通的 Python 模块,它可以从其他文件或包中导入代码。
222+
223+
```python showLineNumbers
224+
import time
225+
from locust import HttpUser, task, between
226+
227+
# 要使文件成为有效的 locustfile,它必须至少包含一个继承自 User 的类。
228+
class QuickstartUser(HttpUser):
229+
# 模拟用户在执行每个任务(见下文)后等待 1 到 5 秒。
230+
wait_time = between(1, 5)
231+
232+
# 用 @task 修饰的方法是 locust 文件的核心。对于每个正在运行的 User,Locust 都会创建一个 greenlet(协程或“微线程”),它将调用这些方法。任务中的代码是按顺序执行的(它只是常规的 Python 代码),因此在收到来自 /hello 的响应之前,不会调用 /world。
233+
@task
234+
def hello_world(self):
235+
self.client.get("/hello")
236+
self.client.get("/world")
237+
238+
# 我们通过使用 @task 装饰两个方法来声明两个任务,其中一个方法被赋予了更高的权重 (3)。当我们的 QuickstartUser 运行时,它将选择声明的任务之一 - 在本例中为 hello_world 或 view_items - 并执行它。任务是随机选择的,但您可以为其赋予不同的权重。上述配置将使 Locust 采摘 view_items 的可能性是 hello_world 的三倍。当任务完成执行后,用户将休眠其指定的等待时间(在本例中为 1 到 5 秒)。然后它将选择一个新任务。
239+
@task(3)
240+
def view_items(self):
241+
for item_id in range(10):
242+
self.client.get(f"/item?id={item_id}", name="/item")
243+
time.sleep(1)
244+
# 只有用 @task 修饰的方法才会被选中,因此你可以用任何你喜欢的方式定义自己的内部帮助程序方法。
245+
def on_start(self):
246+
self.client.post("/login", json={"username":"foo", "password":"bar"})
247+
```
248+
249+
启动压力测试可以在通过 `locust` 命令,这将会启动一个可视化操作界面。输入测试时间、并发用户、目标网址等信息即可查看压测结果图表。
250+
251+
如果在服务器上执行,可以使用命令行`locust --headless --users 10 --spawn-rate 1 -H http://your-server.com`
252+
253+
更多示例可以查看[官方文档](https://docs.locust.io/)

0 commit comments

Comments
 (0)