Skip to main content

ProxyPatternPool

Generic Proxy and Pool classes for Python.

Status Tests Coverage Issues Python Version Badges License

This module provides two classes:

  • Proxy implements the proxy pattern, i.e. all calls to methods on the proxy are forwarded to an internally wrapped object. This allows to solve the classic chicken-and-egg importation and initialization possibly circular-dependency issue with Python modules:

    # File "database.py"
    db = Proxy()
    
    def init_app(config):
        db.set_obj(initialization from config)
    
    # File "app.py"
    import database
    from database import db  # db is a proxy to nothing
    …
    # delayed initialization
    database.init_app(config)
    
    # db is now a proxy to the initialized object
    

    When an internal pool is used, method _ret_obj must be called to return the object to the pool when done with it.

  • Pool implements a full-featured thread-safe pool of things which can be used to store expensive-to-create objects such as database connections, to be shared between threads for instance. The above proxy object creates a pool automatically depending on its parameters.

    This generic pool class can be used independently of the Proxy class.

    It provides numerous hooks to provide callbacks for creation, deletion, stats, tracing, health check… which makes it ideal to manage any kind of expensive resources within a process.

    import ProxyPatternPool as ppp
    
    # start a pool with 2 resources created by "fun"
    pool = ppp.Pool(
        fun = lambda n: f"expensive object {n}",
        min_size=2, max_size=2, timeout=0.5,
    )
    
    # get resources
    a = pool.get(); b = pool.get()  # max_size reached
    try:
        c = pool.get()  # will timeout after 0.5 seconds
        assert False
    except ppp.TimeOut:
        pass
    
    pool.ret(a); pool.ret(b);  # return resources
    
    pool.shutdown()
    del pool
    

License

This code is Public Domain.

All software has bug, this is software, hence… Beware that you may lose your hairs or your friends because of it. If you like it, feel free to send a postcard to the author.

Versions

Sources, documentation and issues are hosted on GitHub. Install package from PyPI. See version details.

Release files for ProxyPatternPool 11.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ProxyPatternPool 11.6
File Size Uploaded
proxypatternpool-11.6.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ProxyPatternPool 11.6
File Interpreter ABI Platform
proxypatternpool-11.6-py3-none-any.whl Python 3 none any Details

Total release size: 24.7 kB

Release files / proxypatternpool-11.6.tar.gz

Download URL proxypatternpool-11.6.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
099577535d616ec79e8fc1b896bfb2533fbe548aeaefea7d40f48ff2fbf4870f
BLAKE2b-256 checksum
How to use checksums
010f7f6d782d33c4c57469fb596114b27fc36a55336a4c78c9adaaa93d2ab456
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / proxypatternpool-11.6-py3-none-any.whl

Download URL proxypatternpool-11.6-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
551e5a9529cc5afbcc6bbf1d480386ea23caaf0db6f72f264e167b9c22f859a6
BLAKE2b-256 checksum
How to use checksums
1a5b37fbf857eda98c951b98e63740cf63e6033fcc41c88e83a21e3fc50652bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

11.6 This release

2 release files

11.5

2 release files

11.4

2 release files

11.3

2 release files

11.2

2 release files

11.1

2 release files

11.0

2 release files

10.3

2 release files

10.2

2 release files

10.1

2 release files

10.0

2 release files

9.7

2 release files

9.6

2 release files

9.5

2 release files

9.4

2 release files

9.3

2 release files

9.2

2 release files

9.1

2 release files

9.0

2 release files

8.5

2 release files

8.4

2 release files

8.3

2 release files

8.2

2 release files

8.1

2 release files

8.0

2 release files

7.4

2 release files

7.3

2 release files

7.2

2 release files

7.1

2 release files

7.0

2 release files

6.1

2 release files

6.0

2 release files

5.0

2 release files

4.0

2 release files

3.0

2 release files

2.1

2 release files

2.0

2 release files

1.1

2 release files

1.0

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page