从函数的多处理和大数据集的解析中省去了麻烦。

processio的Python项目详细描述


Python进程

无需多处理即可运行函数

{1}$ PyPI - StatusDownloadsPyPI - Python Version

一个很好的包,可以帮助您运行多处理函数并获得结果。

安装

pip install processio

用法

在自己的进程中运行函数
^{pr2}$

主命令

# Import the modulefromprocessioimportProcessIO# Start your function with or without argumentsvar=ProcessIO(function,args,kwargs)# Wait for the function to finnish or get the result if its finishedvar.result()

可选命令

# Check if your thread is still working on the function.# This will return True if the function is not completed.var.doing_work()

使用parseIO可以节省列表解析的大量时间

importtimefromprocessioimportParseIOdeflist_parser(list):result=0forlineinlist:result+=get_total_amout(line)returnresultdefdo_some_work():# this will split the list into 4 and run the function on# 4 different processes, that in most cases will almost speed# up the work time by 4.# you can define the number of processes you want to run, but as a# default the module runs on the systems cpu cores - 1parser=ParseIO(list_parser,huge_list)# do stuff or run a while loop to wait for resultwhileparser.doing_work():print('Waiting for processes to finnish')# You can also call .result() and the main thread will wait # for the thread to return your result.result=parser.result()# result comes back as list pr process, so in this case we will get # a list with 4 numbers that we can loop thru.print(result)# Outputs -> [1000, 1000, 1000, 1000] <- exampletotal=0forresinresult:total+=resprint(total)# Outputs -> 4000 <- exampleif__name__=='__main__':# <- its required to execute the function maindo_some_work()

测试

使用以下命令运行测试。在

python -m unittest threadit.tests.test_threadit

变更日志:

看到了吗变更日志.md在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何将cassandra中的行数据转换为与列相关的嵌套json   java如何使用jcr XPath在jcr:content/@jcr:data中搜索?   java在使用openCV进行安卓开发时如何利用手机的广角镜头   java解析扩展了接口,结束了一个潜在的无限循环   位置服务的@Override方法中存在java Android应用程序错误   java本地线程的用途和需求是什么   具有左右子访问的java节点树遍历   java验证JsonWebToken签名   JUL日志处理程序中的java日志记录   嵌入式Java读取给定时间段的串行数据。   java有没有办法从多个URL获取多个图像?   java线程通过等待intent阻止自己发送intent   java Spring MVC解析多部分内容请求   java JPA/Hibernate静态元模型属性未填充NullPointerException   java格式错误的字符(需要引号,得到I)~正在处理   java为什么PrintWriter对象抛出FileNotFoundException?   java Neo4j未正确保存标签   java IE不加载图像