跳转到主要内容

用于限制发送/接收带宽的套接字包装器

项目描述

Python的套接字节流量控制

这个小巧的库包含了一个套接字包装器,可以用来限制它们的发送和/或接收速率到特定值。

它可以用于限制任何使用套接字的Python代码的带宽使用。

示例

import socket
from socket_throttle import LeakyBucket
from socket_throttle.sockets import SocketWrapper


sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
sock.connect(('127.0.0.1', 5000))

# Short syntax, limit sending to 2kB/s and receiving to 100kB/s
sock = SocketWrapper(sock, send=2_000, recv=100_000)

# Longer syntax, create a bucket that can be shared by multiple sockets
# Receive speed is unlimited
send_bucket = LeakyBucket(100_000, 500_000)
sock = SocketWrapper(sock, send=send_bucket)

# It works with files too
from socket_throttle.files import FileWrapper

with open('data.bin', 'rb') as file:
    file = FileWrapper(file, read=100_000)
    file.read(...)

项目详情


下载文件

下载适用于您平台的项目文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

socket_throttle-0.2.1.tar.gz (3.7 kB 查看哈希值)

上传时间:

构建分布

socket_throttle-0.2.1-py3-none-any.whl (5.0 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面