BatchScript
使用多进程+线程池+队列运行你的方法
$> pip3 install BatchScript
# or
$> git clone https://github.com/TaylorHere/BatchScript.git && cd BatchScript && pip3 install -e .
# and you can test it
$> cd BatchScript && python3 test.py
from master import Master
from worker import Worker
import helper
import os
class Config():
MaxWorkerSize = os.cpu_count() - 1 #worker数量
MaxThreadPoolSize = 1024 #每个worker的线程池大小
ThreadQueueWaitTimeout = 0.01 #worker在job队列上获取数据的超时, 超时后会立即开始批量线程提交
WorkerGetBatchSize = MaxThreadPoolSize #额定批大小, 如果worker获取数据时不超时, 那么在获取都这个数量后便开始批量线程提交
JobsResultsQueueNum = MaxWorkerSize #jobs 和 results 队列对的数量, 该数量如果小于worker数量, 则最后一对会被未分配的worker共用, 共用队列可能会导致锁操作增加
ResultsBatch = True #将一个batch的所有result当作一个result放入result 队列中
master = Master(func=helper.sleep, config=Config())
master.start()
for i in range(1000):
master.job_put(0.01)
while True:
print(master.result().get())
链接多个 master
from master import Master
from worker import Worker
import helper
master = Master(func=helper.sleep)
master.start()
for i in range(1000):
master.job_put(0.01)
another_master = Master(func=print, connection=master)#该master会将connection的master的results队列作为jobs队列, 如果该master的队列对比链接master的队列对数量少, 会造成链接master的result不能被全部消耗
another_master.start()
采用 多进程启动Worker, worker维护线程池运行函数的方案 master内建和worker关联的多个任务队列和对应的多个结果队列 worker按batch从任务队列中获取数据并使用线程池提交运行 批量结束后将任务结果put到结果队列
你可以在config中调整
import os
MaxWorkerSize = os.cpu_count() - 1 #worker数量
MaxThreadPoolSize = 1024 #每个worker的线程池大小
ThreadQueueWaitTimeout = 0.01 #worker在job队列上获取数据的超时, 超时后会立即开始批量线程提交
WorkerGetBatchSize = MaxThreadPoolSize #额定批大小, 如果worker获取数据时不超时, 那么在获取都这个数量后便开始批量线程提交
JobsResultsQueueNum = MaxWorkerSize #jobs 和 results 队列对的数量, 该数量如果小于worker数量, 则最后一对会被未分配的worker共用, 共用队列可能会导致锁操作增加
ResultsBatch = True #将一个batch的所有result当作一个result放入result 队列中
Metadata
Release files for BatchScript 0.0.9
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 | |
|---|---|---|---|---|
| BatchScript-0.0.9.tar.gz | 4.2 kB | Without provenance | Details |
Release files / BatchScript-0.0.9.tar.gz
| Download URL | BatchScript-0.0.9.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
47565f77cc99aab1e8e721c62b30fc37880a33a9b57e6c370c97eaf6767bfff8
|
|
BLAKE2b-256 checksum How to use checksums |
ae323642b800d4c136803404d1bc09a7e922264a0fd848df6e3736f62e34bfc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.10
|
Security for BatchScript 0.0.9
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.