热门

最新

红包

立Flag

投票

同城

我的

发布
weixin_32759777
东方佑
2 年前
trueweixin_32759777

python 多进程存储返回值
import warnings
import time
from multiprocessing import Manager
from multiprocessing.dummy import freeze_support

import pandas as pd
from multiprocessing.pool import Pool

def get_pool(tu):
text = "djaiojeiwoiobnaeoijojxocvmoiojes" * 10000
text_df = pd.DataFrame({"voc_b_id": list(text), "count": [1] * len(text)})
tu.append(text_df.groupby("voc_b_id", as_index=False)["count"].count())

if __name__ == '__main__':
freeze_support()
warnings.filterwarnings('ignore')
manager = Manager()
return_list = manager.list()
pool=Pool(8)
start=time.time()
for i in range(200):

pool.apply_async(get_pool,args=(return_list,))
pool.close()
pool.join()
print(time.time()-start)
pd.concat(list(return_list)).groupby("voc_b_id", as_index=False)["count"].count()

CSDN App 扫码分享
分享
1
1
打赏
  • 复制链接
  • 举报
下一条:
这篇博客多次加入【CSDN精选】,感谢官网平台的认可,感谢小伙伴们的鼓励,很多时候可能我们并不知道自己很优秀,所以要多分享,多交流,顺带着多看看这篇优秀的博客,哈哈,https://blog.csdn.net/xingyu_qie/article/details/129658186
立即登录