日常开发人员的简单并行性
python-parallel的Python项目详细描述
平行的
Bringing parallelism closer to humans ✨
重要:parallel
处于早期阶段。欢迎提出任何问题和建议。请submit an issue。
开始
安装:
$ pip install python-parallel
并行化:
@parallel.decoratedefdownload_and_store(url):resp=requests.get(url)result=store_in_db(resp.json())returnresultresults=download_and_store.map(['https://python.org','https://python-requests.com','https://rmotr.com'],timeout=5,max_workers=4)
还有更多功能可以parallel
:
- 高级参数传递(命名参数,附加项)。
- 失败的任务和静默模式。
- 异步api(带有上下文管理器)。
- 自动重试
- 使用简单属性
thread
&;process
在多线程和多处理之间进行选择。
查看https://python-parallel.readthedocs.io/en/latest/上的文档
快速文档
parallel
简化了python代码中并行化任务的过程。有时,您有一个函数要与不同的参数并行调用多次(如上面的示例)。
在其他一些情况下,您希望并行执行多个函数。示例:
@parallel.decorateddefget_price_bitstamp(crypto):pass@parallel.decorateddefget_price_bitfinex(crypto):pass@parallel.decorateddefget_price_coinbase(crypto):passprices=parallel.par({'stamp':get_price_bitstamp.future(crypto='BTC'),'finex':get_price_bitfinex.future(crypto='BTC'),'base':get_price_coinbase.future(crypto='BTC'),})# prices is a dict-like structureprint("Price of Bitstamp: {}".format(prices['stamp']))print("Price of Coinbase: {}".format(prices['base']))
贡献
运行测试
$ pip install -r dev-requirements.txt
$ py.test -n 4 tests/
编写和生成文档:
$ python docs/live_docs.py