Skip to main content

Provides a thread safe resource pool

Project description

pyresourcepool

Github: https://github.com/bensonrodney/pyresourcepool

Simple thread-safe resource pool to wait and/or use a limited set of resources, where a resource is a python object.

An example use case, and the reason this module was created, is when there exists a queue of actions to be performed but on a limited number of resources. Workers take actions from the queue and pull resources from the resource pool, perform the action and return the resource to the pool. The worker then pulls the next action from the queue and another recourse and this continues until there are no more actions in the queue.

Basically, you create a resource pool with a list of objects and then processes in multiple threads can use those resources and return them to the pool when finished.

Example usage:

from pyresourcepool.pyresourcepool import ResourcePool

# create a list of instances of "SomeObjectClass" class
objects = [SomeObjectClass() for o in range(10)]

# create the resrouce pool
rp = RecourcePool(objects)

# using an object would normally be done in some worker thread
# but for this example we'll just do it here
# Using the with block will wait for a resource to be available, return that
# resource and once the with block is exited, the resource will be returned
# to the pool.
with rp.get_resource() as obj:
    do_stuff_with_object(obj)

# at this point, outside the 'with' block, the object will have been
# returned to the object pool.

If a resource/object becomes invalid and should not be used again it can be removed from the pool with the pool's remove_resource(obj) method. An exception will be raised when the last resource is removed from the pool or when an attempt is made to get a resource from an empty pool.

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

PyResourcePool-0.1.7.tar.gz (4.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

PyResourcePool-0.1.7-py3.6.egg (6.0 kB view details)

Uploaded Egg

PyResourcePool-0.1.7-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file PyResourcePool-0.1.7.tar.gz.

File metadata

  • Download URL: PyResourcePool-0.1.7.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.8

File hashes

Hashes for PyResourcePool-0.1.7.tar.gz
Algorithm Hash digest
SHA256 e7a77b79246d11dc2eff99ad3a3670ceff22e6e5c21dcbff298a7c6d00a0885e
MD5 5597be7ab37c3e77d4aaf89ca7190b74
BLAKE2b-256 934ba66ac9e7d0fbe7fa52c1430c1e7612ae2663417926639544bfd50703d99c

See more details on using hashes here.

File details

Details for the file PyResourcePool-0.1.7-py3.6.egg.

File metadata

  • Download URL: PyResourcePool-0.1.7-py3.6.egg
  • Upload date:
  • Size: 6.0 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

File hashes

Hashes for PyResourcePool-0.1.7-py3.6.egg
Algorithm Hash digest
SHA256 577a91f3d54da74c9f1754fdc43c20889eb8eb600e6cbb17464aa8d081980ec4
MD5 0ecce7e843faac9f52245324c1f14cc1
BLAKE2b-256 0c05f2f14b77d9794dd08fae1a43041a416948fe7f5dc064ea138bbd7167d7c7

See more details on using hashes here.

File details

Details for the file PyResourcePool-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: PyResourcePool-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.8

File hashes

Hashes for PyResourcePool-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 003b58cc681eb9d2f22d7f18a267acef32f2b76be5143e61a46e88e0530d7ec3
MD5 9ddb8f87d6d2ef252c82f37fb24ff6a8
BLAKE2b-256 80a62ff7ee31a06ff51502b1185b07fddff690f98032293c29189d6b56c4a4c9

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