Skip to main content

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

https://querypool.readthedocs.io/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

querypool-0.1.0rc2.tar.gz (6.9 kB view details)

Uploaded Source

File details

Details for the file querypool-0.1.0rc2.tar.gz.

File metadata

  • Download URL: querypool-0.1.0rc2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for querypool-0.1.0rc2.tar.gz
Algorithm Hash digest
SHA256 182a1d47d94cd6cf0d595f66d0d0dd434f5e4068e7784729369004813e6128e2
MD5 c89027226b201eb51f35f3ed910db876
BLAKE2b-256 2fb238339a954318e5ea625b453778865b38a8fb8c1374e53d3031c69b71db8b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page