Skip to main content

Eloope

事件循环引擎, 主要功能:

1. 异步执行, 解决io密集型任务
2. 支持搭建多进程, 分布式运行
3. 支持断点续爬
4. 提供日志系统

目录:

安装

pip install eloope --upgrade

使用

  • 首行导入 eloope 模块

单进程

from eloope import engine, get_current_engine, logger

def task(code):
    logger.info(f'{get_current_engine().name} --- {code}')

engine.add_tasks(fn=task, param_groups=[[code] for code in range(100)])
engine.run()
  • 单进程 demo: spider_dili.py
  • 通过 get_current_engine 函数获得当前运行engine

多进程

开启服务

from eloope import run_server

run_server(load_file=None, dump_path='.', log_path=None, host='localhost', port=6991)
  • load_file: 加载任务文件
  • dump_path: 任务文件保存路径
  • log_path: 日志保存路径, 为 None 时将不保存日志文件

运行客户端

from eloope import Manager, get_current_engine, logger

def task(code):
    logger.info(f'{get_current_engine().name} --- {code}')

if __name__ == '__main__':
    # Manager 创建多进程
    manager = Manager(engine_names=['engine1', 'engine2'], host='localhost', port=6991)
    manager.add_tasks(fn=task, param_groups=[[code] for code in range(100)])
    manager.run()
  • 多进程客户端需要在 if __name__ == '__main__': 语句中启动
  • 多进程 demo: multi_progress.py

分布式

  • 与 多进程 相同, 部署项目文件, 连接同一服务

命令式

>>> eloope <command> <host=localhost> <port=6991>
command 说明
stop 停止向客户端发送任务
start 开始向客户端发送任务
save 保存当前服务器上的任务
quit 强制退出服务和所有客户端
task_total 任务总数量
task_count 任务当前数量
start_time 服务开始时间
connect 连接服务

日志

from eloope import logger

logger.info('hello world!')
logger.debug('hello world!')
logger.result('hello world!')
logger.warning('hello world!')
logger.error('hello world!')
logger.system('hello world!')
  • 导入 eloope 模块将会屏蔽掉其他模块的日志系统

setting

from eloope import setting

# 客户端运行中连接失败回调函数
# 参数: engine(Engine 实例), repeat_count(重复连接次数)
# 返回: True(重新连接), False(断开连接退出程序)
setting.connection_interrupt_callback = connection_interrupt_callback

setting.send_interval = 1  # 客户端连接服务器间隔
setting.log_path = None  # 本地日志保存路径

# 日志级别过滤
setting.log_filter = ('info', 'debug', 'result', 'warning', 'error', 'system')

API

Engine(name='engine', size=50)

  • name: 名称标识
  • size: 任务池大小
Attribute 说明
name 名称
is_run 运行状态
task_count 任务数量
free_count 任务池剩余空间
task_pool 任务池
run() 阻塞运行
add_task(fn, *params) 添加单个任务
add_tasks(fn, param_groups) 添加多个任务, 同一个函数不同参数

Manager(engine_names=None, host='localhost', port=6991)

  • engine_names: engine 名称标识列表 (每一个 engine 都为单独进程)
  • host: 服务器地址
  • post: 服务器端口
Attribute 说明
create_engines(engine_names, size=50) 创建多个 engine
add_task(fn, *params) 添加单个任务
add_tasks(fn, param_groups) 添加多个任务, 同一个函数不同参数
run() 非阻塞运行

下次更新内容

1. 添加任务执行的优先级.
2. 可以指定 enigne 执行任务.
3. 添加任务执行失败自定义回调函数.
4. 可以选择同步或异步 engine 类型.
5. 重新设计日志系统
6. 添加 UI 控制面板
7. 添加测试文件

Metadata

Release files for eloope 2019.6.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eloope 2019.6.8
File Size Uploaded Provenance Actions
eloope-2019.6.8.tar.gz 11.6 kB Without provenance Details for eloope-2019.6.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for eloope 2019.6.8
File Interpreter ABI Platform Actions
eloope-2019.6.8-py3-none-any.whl Python 3 none any Details for eloope-2019.6.8-py3-none-any.whl

Total release size: 25.0 kB

Release files / eloope-2019.6.8.tar.gz

Download URL eloope-2019.6.8.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7b85d7cd31fda56a1027b6a5667ad93d5f4325f6cd43f3e6d423b2165a7d786a
BLAKE2b-256 checksum
How to use checksums
d7609c9a529c2dc327a5b1de0f08505e3297c56773a8cf5b105d511cb41df48f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

Release files / eloope-2019.6.8-py3-none-any.whl

Download URL eloope-2019.6.8-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
941de56b9909891825e134264066c982e20ee5c5548c39f110e631da6d8af962
BLAKE2b-256 checksum
How to use checksums
3c48612c93617b67cae8bcad45ecdde26601c8383b9babf82475c19655bc4883
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

Security for eloope 2019.6.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page