queuepool - A multithread-safe resource pool based on synchronized queue
The main problem with psycopg2.pool (https://github.com/psycopg/psycopg2/blob/master/lib/pool.py), for example, is that the pool raises an exception (instead of blocking) when there are no more connections in the pool, and you either have to match the number of connections to the number of workers, or implement retry logic. Also, it doesn’t implement connection recycling (on timeout or usage count), and therefore, doesn’t fully address issue with stale connections and suited less (scales worse) for large production installations.
This implementation is based on synchronized queue (https://docs.python.org/3/library/queue.html), and thus multithred safe. This is a streamlined port from Java version that was implemented about ten years ago and that has since then been running in heavy production evironment of one of our financial clients.
This implementation features:
A pool of generic resources that can be extended for specific resources like psycopg2 connections. Psycopg2 connection pool implementation is provided.
On-demand lazy resource opening.
Idle and open timeout recycling. Requires user code to execute pool.recycle() method periodically (or start recycler thread by pool.startRecycler()), for example, once a minute. If this method isn’t executed periodically, then the recycling is performed only when the resource are either taken or returned back to the pool, and therefore, the pool can accumulate a number of idle connections that exceed the idle or open timeouts.
Usage count recycling.
Recycling on exception.
Recycling on a resource status.
Context manager allows to use the pool with “with” context manager so that the resources could be returned safely to the pool.
LIFO queue helps the pool keep number of open resources to the minimum.
This pool can be utilized successfully in large production installations as it tries to keep the number of open resources to the minimum, yet providing sufficient number of “hot” (open) resources to avoid open/close cost.
License
OSI Approved 3 clause BSD License
Prerequisites
Python 3.7+ (with queue)
For psycopg2 connections: psycopg2 2.8.2+
Installation
If prerequisites are met, you can install queuepool like any other Python package, using pip to download it from PyPI:
$ pip install queuepool
or using setup.py if you have downloaded the source package locally:
$ python setup.py build $ sudo python setup.py install
Metadata
Release files for queuepool 1.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| queuepool-1.3.2.tar.gz | 8.2 kB | Without provenance | Details for queuepool-1.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| queuepool-1.3.2-py3-none-any.whl | Python 3 | none | any | Details for queuepool-1.3.2-py3-none-any.whl |
Total release size: 20.7 kB
Release files / queuepool-1.3.2.tar.gz
| Download URL | queuepool-1.3.2.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0d6770ba588add74240d626267fa787bf98b407bff36edadc048d26d0abd550
|
|
BLAKE2b-256 checksum How to use checksums |
f9b87b797b11342434ab5648bd9a548e03d221a6044a9b0042c9b1ec4bd4b5b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
|
Release files / queuepool-1.3.2-py3-none-any.whl
| Download URL | queuepool-1.3.2-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be93fbcf49c11e88a31557658d9ba953d5b0a30b6ccc7e8cc6b0c1c273a1a88d
|
|
BLAKE2b-256 checksum How to use checksums |
28efb364259c14bbd7075bd5f2227ef74e09504d22277cf7e86aa2fca65d482c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
|
Security for queuepool 1.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.