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-1.1.0.tar.gz (8.2 kB view details)

Uploaded Source

File details

Details for the file querypool-1.1.0.tar.gz.

File metadata

  • Download URL: querypool-1.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for querypool-1.1.0.tar.gz
Algorithm Hash digest
SHA256 70937e52838d79b2eb99846b3d0e5d583f1dd16bd8eb6f13fc63861daccdc904
MD5 6fdff9cda34e74fa9c946c56f0ae23cc
BLAKE2b-256 8736d38c4c0317748cd4f9596af62cacdb80d68ccc7f1032d4a7c5726dd86cf2

See more details on using hashes here.

Supported by

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