带有缓存和提前返回的执行池
项目描述
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()
文档
项目详情
关闭
querypool-1.0.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2b3172bb4cf938f3e67b1e2d3d9c2468ca63bcee7875b5f8ef85a2d2e0e7154b |
|
MD5 | 9dda3a53f1fe39808bdaf7cbb50b2a1a |
|
BLAKE2b-256 | af0a4ebaa5c589c22d46ac47d0c76c20eb63046181872e846fc8285133ff66aa |