ProducerConsumerPattern
通过装饰器方式实现生产者消费者模式。 可以作用于函数、类的方法上,使其变为异步调用,同时,转变为逐次调用,批量执行。方便将零碎的调用转变为批量形势进行统一执行。
Github 地址:ProducerConsumerPattern
安装
pip install prodconpattern
示例代码
函数调用:逐次调用 -> 异步逐次调用
from prodconpattern import ProducerConsumer
@ProducerConsumer(threshold=3)
def method_single_invoke(n):
"""函数调用:逐次调用 -> 异步逐次调用"""
print('method_single_invoke ->', n)
import time
# 函数调用:逐次调用 -> 异步逐次调用
for n in range(10):
print("call -> method_single_invoke(%d)" % n)
method_single_invoke(n)
time.sleep(6)
函数调用:逐次调用 -> 异步批量调用
from prodconpattern import ProducerConsumer
@ProducerConsumer(threshold=3, pass_arg_list=True)
def method_list_invoke(n):
"""函数调用:逐次调用 -> 异步批量调用"""
print('method_list_invoke ->', n)
import time
# 函数调用:逐次调用 -> 异步批量调用
for n in range(10):
# time.sleep(1)
print("call -> method_list_invoke(%d)" % n)
method_list_invoke(n)
time.sleep(6)
对象方法调用:逐次调用 -> 异步批量调用
from prodconpattern import ProducerConsumer
class AClass:
@ProducerConsumer(threshold=3, pass_arg_list=True, is_class_method=True)
def class_method_list_invoke(self, n):
"""对象方法调用:逐次调用 -> 异步批量调用"""
print(self.__class__.__name__, "print_method", n)
import time
# 对象方法调用:逐次调用 -> 异步批量调用
aaa = AClass()
for n in range(10):
print("call -> class_method_list_invoke(%d)" % n)
aaa.class_method_list_invoke(n)
time.sleep(6)
更多例子参考 example.py 文件
Metadata
Release files for prodconpattern 0.2.1
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 |
|---|---|---|---|---|
| prodconpattern-0.2.1.tar.gz | 4.0 kB | Without provenance | Details for prodconpattern-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| prodconpattern-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for prodconpattern-0.2.1-py3-none-any.whl |
Total release size: 8.9 kB
Release files / prodconpattern-0.2.1.tar.gz
| Download URL | prodconpattern-0.2.1.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0422299795b0bd3377c75fd362fe5616837fc0cd85857444c8955c734386ef1b
|
|
BLAKE2b-256 checksum How to use checksums |
e7c7f312cde19fbb505e9a8087d8f340b86a874946a2de9b8de406257d149816
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.13.0 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.5.5
|
Release files / prodconpattern-0.2.1-py3-none-any.whl
| Download URL | prodconpattern-0.2.1-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21fa2923b29decc739de23f3e4319ad6e7d2345e9eb6449beb7049bf66f7cc09
|
|
BLAKE2b-256 checksum How to use checksums |
2adb332c2b9c841f38913f784ad651b7c1216c32326267bb6813f2554bf5ef9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.13.0 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.5.5
|
Security for prodconpattern 0.2.1
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.