A generic object pool implementation
Project description
generic-pool
generic-pool is a generic object pool for python inspired by the node.js library.
You can use it to build your own resource pools, e.g. to manage file handles, connections or similar.
Install
Install generic-pool
from pypi using your favourite package manager.
# If you use poetry
poetry add generic-pool
# If you use pip
pip install generic-pool
Usage
from random
from generic_pool import Factory
from generic_pool import Pool
class IntValue:
def __init__(self):
self.value = random.rand
pass
class FortyTwoFactory(Factory):
def create(self) -> IntValue:
return IntValue()
def validate(self, item: IntValue) -> bool:
return item.value == 42
def destroy(self):
# free resources, not applicable here
pass
factory = FortyTwoFactory()
pool = Pool(factory)
item = pool.acquire()
try:
assert item.value == 42
finally:
pool.release(item)
with pool.acquire(item):
assert item.value == 42
License
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
generic-pool-0.1.2.tar.gz
(3.9 kB
view details)
Built Distribution
File details
Details for the file generic-pool-0.1.2.tar.gz
.
File metadata
- Download URL: generic-pool-0.1.2.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Linux/5.13.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 520d31261ac9ea3f9b361bd4fb06004d2848b555ede31817910b336f3cbccca4 |
|
MD5 | df3174916f614420042454aead77aa93 |
|
BLAKE2b-256 | 1ec89f870141c903f05f22bcac5a2de380a5c4c32b634910fc9b027560037e26 |
File details
Details for the file generic_pool-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: generic_pool-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Linux/5.13.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a409e05168aed637616477282a9079bd2fbc0829c42a96226697614e96d11ba1 |
|
MD5 | 8f9dd41a8f37c10e43ca83cc0a4edfc0 |
|
BLAKE2b-256 | 19304c5c5f0403b26338ff74124b1b544fa1415ec51220a11e715fc5bdecd418 |