Execution pool with caching and early return
Project description
querypool
Execution pool with caching and early return for python.
Query pools let a query run in the background when it doesn't return within a given timeout. In that case the result of the previous query is returned or raised. If there is no result, the default value is returned.
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()
Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
querypool-1.0.0.tar.gz
(7.4 kB
view details)
File details
Details for the file querypool-1.0.0.tar.gz
.
File metadata
- Download URL: querypool-1.0.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b3172bb4cf938f3e67b1e2d3d9c2468ca63bcee7875b5f8ef85a2d2e0e7154b |
|
MD5 | 9dda3a53f1fe39808bdaf7cbb50b2a1a |
|
BLAKE2b-256 | af0a4ebaa5c589c22d46ac47d0c76c20eb63046181872e846fc8285133ff66aa |