线程池, 固定指定数量的线程来执行任务, 避免重复创建和销毁线程时的资源消耗
注意:
如果任务数量超过线程数量, 超出的任务会等待有正在执行的任务执行完毕后, 在有空闲线程时才会执行
测试代码:
if __name__ == '__main__':
import time
import threading
p = ThreadPool(2)
@p.task()
def fun(a, c):
print(a, '开始', time.strftime(' %H:%M:%S', time.localtime()))
for i in range(c):
time.sleep(0.01)
print(a, ' 结束', time.strftime(' %H:%M:%S', time.localtime()))
fun('aa', 100)
fun('bb', 100)
fun('cc', 100)
fun('dd', 100)
p.close()
p.join()
print('--end--')
注意:
如果任务数量超过线程数量, 超出的任务会等待有正在执行的任务执行完毕后, 在有空闲线程时才会执行
测试代码:
if __name__ == '__main__':
import time
import threading
p = ThreadPool(2)
@p.task()
def fun(a, c):
print(a, '开始', time.strftime(' %H:%M:%S', time.localtime()))
for i in range(c):
time.sleep(0.01)
print(a, ' 结束', time.strftime(' %H:%M:%S', time.localtime()))
fun('aa', 100)
fun('bb', 100)
fun('cc', 100)
fun('dd', 100)
p.close()
p.join()
print('--end--')
Metadata
Release files for zthreadpool 1.0.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 | |
|---|---|---|---|---|
| zthreadpool-1.0.1.tar.gz | 3.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zthreadpool-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.6 kB
Release files / zthreadpool-1.0.1.tar.gz
| Download URL | zthreadpool-1.0.1.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
86e2df8df76a8269e04235adf3db05e5f6bfbadfe8569408143b3d830776ccc3
|
|
BLAKE2b-256 checksum How to use checksums |
20827b99a03fe31595fb276e1eaf7cfc3ad5a2bf1e81026fc40d435ccf10bdf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
|
Release files / zthreadpool-1.0.1-py3-none-any.whl
| Download URL | zthreadpool-1.0.1-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8fecc5d6a4a5e5ab8d5ab161796a8c06f9faa3dfa42f1e82bc7cbdf0a297a5cf
|
|
BLAKE2b-256 checksum How to use checksums |
3606116ae0e1c77b3988ef903506786f4cb3a338802f87d291d666f57193e94c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
|
Security for zthreadpool 1.0.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.