Skip to main content

A lazy connection context manager

A lazy connection context manager

使用说明

LazyConnection 是一个线程安全的连接管理器,它将会创建一个连接上下文(context),这个上下文管理一堆在它上面注册的工场函数(factory)。

  • 在context 的生命周期范围内,factory 将会根据使用到的情况按需创建(最多只会被创建一次), 通过以 context 上注册的名字作为属性来访问, 可得到该 factory 的一个实例。

  • 在context 的生命周期结束时,将会自动执行清理工作,factory 的实例会被销毁,如果有 close 方法也将被调用。

使用范例:

from lazyconn import LazyConnection

def create_test1_client():
    return snow(host='127.0.0.1', port=1234)

def create_test2_client1():
    return wish(host='127.0.0.1', port=1235)

# register
LazyConnection.register_factory('test', create_test1_client)
LazyConnection.register_factory('test2', create_test2_client)

# context life
with LazyConnection() as conn:
    conn.test1.hello('wayhome')

lg 是一个线程安全的全局对象,它只在连接上下文中有效,它的 conn 属性对应一个连接上下文。

使用范例:

from lazyconn.globals import lg

 with LazyConnection() as conn:
     conn.test1.hello('wayhome')
     lg.conn.test1.hello('wayhome2')

thread_safe 是一个装饰器, 被装饰的函数将会在一个连接上下文中执行。lg 对象可以在被装饰的函数内部使用。

使用范例:

from lazyconn import thread_safe

@thread_safe
def test():
    lg.conn.test1.hello('wayhome3')

History

0.1.0 (2013-08-11)

  • First release on PyPI.

Metadata

Release files for lazyconn 0.1.0

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

Source distribution (sdist)

Source distribution for lazyconn 0.1.0
File Size Uploaded Provenance
lazyconn-0.1.0.tar.gz 7.8 kB Without provenance Details

Release files / lazyconn-0.1.0.tar.gz

Download URL lazyconn-0.1.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8d1665f98ec0e9d6132655ea576707c4afbc3d11caa6e67ec6b56be55f96b190
BLAKE2b-256 checksum
How to use checksums
79a088d7bd1c9f6beaa70a52a3752b93f4eb596ef1df0143e11b7f11aa5a299a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for lazyconn 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

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