跳转到主要内容

带有缓存和提前返回的执行池

项目描述

querypool

Python的执行池,具有缓存和提前返回功能。

查询池允许在查询未在给定超时时间内返回时在后台运行。在这种情况下,将返回或抛出上一个查询的结果。如果没有结果,则返回默认值。

import requests
from querypool.pools import CooperativeQueryPool

pool = CooperativeQueryPool(timeout=0.001)
url = "https://jsonplaceholder.typicode.com/photos"

# Returns None because the query times out.
response = pool.execute(requests.get, args=(url,), default=None)
assert response is None

# Increase the timeout to let the query finish.
# The same function with the same arguments is still running so
# all this does is wait for the result of the previous call.
response = pool.execute(requests.get, args=(url,), default=None, timeout=3)
response.raise_for_status()

# Returns the previous result because the query times out.
response = pool.execute(requests.get, args=(url,), default=None)
response.raise_for_status()

文档

https://querypool.readthedocs.io/

项目详情


下载文件

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

源代码分发

querypool-1.0.0.tar.gz (7.4 kB 查看哈希值)

上传时间 源代码

由以下支持