https://blog.csdn.net/qq_39694935/article/details/84552076

【Python】multiprocessing Pool 进程间通信共享

直接上代码:

from tqdm import tqdm
from multiprocessing import Pool
import functools
from pymongo import MongoClient
mdb = MongoClient('120.xx.26.xx:20002', username='xx', password='xxxxx') # 三种main的写法只写一种即可 def create_data(image): # TODO 具体处理逻辑
print(image)
return str(image) def main_deal(): num_processor = 20
p = Pool(num_processor)
images = mdb['db_name']['image'].find(no_cursor_timeout=True).batch_size(200) fw = open('result.txt', 'w+')
for result in tqdm(p.imap(create_data, images), total=images.count()):
fw.write(result + '\n')
fw.close() for _ in tqdm(p.imap_unordered(create_data, images)):
pass
p.close()
p.join() def main_deal(): num_processor = 20
p = Pool(num_processor) images = mdb['goodlook']['image_generated_data'].find(no_cursor_timeout=True).batch_size(200)
fw = open('result.txt', 'w+')
for result in tqdm(p.imap_unordered(create_data, images)):
fw.write(result + '\n')
fw.close() p.close()
p.join() def main_deal():
num_processor = 20
p = Pool(num_processor) images = mdb['goodlook']['image_generated_data'].find(no_cursor_timeout=True).batch_size(200)
fw = open('result.txt', 'w+') pt = functools.partial(create_data)
for result in tqdm(p.imap_unordered(pt, images)):
fw.write(result + '\n')
fw.close() p.close()
p.join() if __name__ == '__main__':
main_deal()

  

python多进程执行任务的更多相关文章

  1. Python多进程编程

    转自:Python多进程编程 阅读目录 1. Process 2. Lock 3. Semaphore 4. Event 5. Queue 6. Pipe 7. Pool 序. multiproces ...

  2. Python多进程(1)——subprocess与Popen()

    Python多进程方面涉及的模块主要包括: subprocess:可以在当前程序中执行其他程序或命令: mmap:提供一种基于内存的进程间通信机制: multiprocessing:提供支持多处理器技 ...

  3. Python多进程使用

    [Python之旅]第六篇(六):Python多进程使用   香飘叶子 2016-05-10 10:57:50 浏览190 评论0 python 多进程 多进程通信 摘要:   关于进程与线程的对比, ...

  4. Python多进程并发(multiprocessing)用法实例详解

    http://www.jb51.net/article/67116.htm 本文实例讲述了Python多进程并发(multiprocessing)用法.分享给大家供大家参考.具体分析如下: 由于Pyt ...

  5. python 多进程开发与多线程开发

    转自: http://tchuairen.blog.51cto.com/3848118/1720965 博文作者参考的博文:  博文1  博文2 我们先来了解什么是进程? 程序并不能单独运行,只有将程 ...

  6. day-4 python多进程编程知识点汇总

    1. python多进程简介 由于Python设计的限制(我说的是咱们常用的CPython).最多只能用满1个CPU核心.Python提供了非常好用的多进程包multiprocessing,他提供了一 ...

  7. 【转】Python多进程编程

    [转]Python多进程编程 序. multiprocessingpython中的多线程其实并不是真正的多线程,如果想要充分地使用多核CPU的资源,在python中大部分情况需要使用多进程.Pytho ...

  8. Python 多进程multiprocessing

    一.python多线程其实在底层来说只是单线程,因此python多线程也称为假线程,之所以用多线程的意义是因为线程不停的切换这样比串行还是要快很多.python多线程中只要涉及到io或者sleep就会 ...

  9. Python多进程池 multiprocessing Pool

    1. 背景 由于需要写python程序, 定时.大量发送htttp请求,并对结果进行处理. 参考其他代码有进程池,记录一下. 2. 多进程 vs 多线程 c++程序中,单个模块通常是单进程,会启动几十 ...

随机推荐

  1. 【IOI2014】Game

    题目简述 健佳是一个喜欢做游戏的小男生.当有人问问题时,他更喜欢通过玩游戏的方式作答,而不是直接回答.健佳碰到了他的朋友梅玉,跟她讲了台湾的航空网.在台湾有 $n$ 个城市(编号为 $0, \dots ...

  2. java正则过虑字符

    public static void main(String[] args) { String testrString = "{\"abc\" : \"[123 ...

  3. 智能手机+DIY红外=万能遥控器

    目前好像只有:三星S4.,努比亚大牛,华为荣耀3等几款新机才有红外遥控功能,那我们使用的手机没有这个功能怎么办?不要急我有办法呵呵,本次DIY材料好找又简单,大家都可以亲自试一试! DIY材料:红外二 ...

  4. js利用offsetWidth和clientWidth来计算滚动条的宽度

    原文: http://www.haorooms.com/post/js_scroll_width 参考: https://www.cnblogs.com/benxiaohai-microcosm/p/ ...

  5. UVA 12338 - Anti-Rhyme Pairs(后缀数组+RMQ)

    UVA 12338 - Anti-Rhyme Pairs 题目链接 题意:给定一些字符串,每次询问求出两个字符串的最长公共前缀的长度 思路:把字符串排序,就能求出height和rank数组,然后利用R ...

  6. dos alias/cname address

    diego@localhost sdk/include/Poco/Net]# dig b.wpss.cn ; <<>> DiG - <<>> b.wps ...

  7. python(27)- 面向对象练习Ⅰ

    一:定义如下类,并最大程度地重用代码(继承,派生:子类重用父类方法,组合) 老师类 学生类 分数类 课程类 生日类 class People: def __init__(self,name,age,b ...

  8. ActiveMQ测试工具

    1. 测试工具 目前使用两种测试工具进行压力测试 1. Jmeter 测试单客户端收发多主题,测试高并发,大数据量时的接收效率 2. emqtt_benchmark测试多客户端收发主题,测试高吞吐量下 ...

  9. web前端面试系列 - 算法( 数组去重 )

    1. 思路:设置一个临时数组temp,然后遍历要去重的数组arr,如果arr中的元素能够在temp中找到,则跳过此元素,否则将此元素存入temp,最后返回temp. 实现一 function uniq ...

  10. linux 块设备驱动(四)——简单的sbull实例

    #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> # ...