import logging
import datetime
import multiprocessing
FORMAT = "%(process)d %(processName)s %(thread)d %(message)s"
logging.basicConfig(level=logging.INFO, format=FORMAT)
def calc(i):
sum = 0
for _ in range(100000000):
sum += 1
logging.info('{}.in function'.format(sum))
return sum
if __name__ == '__main__':
start = datetime.datetime.now()
pool = multiprocessing.Pool(2)
for i in range(5):
pool.apply_async(calc, args=(i, ),
callback=lambda x: logging.info('{}.in callback'.format(x)))
pool.close()
pool.join()
delta = (datetime.datetime.now() - start).total_seconds()
print(delta)
multiprocessing Pool 进程池
原创windcharger 博主文章分类:Python线程./进程 ©著作权
文章标签 multiprocessing Pool 文章分类 Python 后端开发
下一篇:VueRouter代码笔记
-
如何解决 Odoo 的 psycopg2.pool.PoolError: The Connection Pool Is Full 错误:增加 PostgreSQL 最大连接数
修改数据库最大连接数
PostgreSQL 配置文件 postgresql -
python学习:multiprocessing多进程-Pool进程池模块
Multiprocessing.Pool可以提供指定数量的进程供用户调用,当有新的请求提交到p
python 学习 开发语言 子进程 进程池 -
python 多进程 —— multiprocessing.Pool
Pool如果要启动大量的子进程,可以用进程池
python 多进程 进程池 异步 cpu -
python multiprocessing pool 指定进程名 python multiprocessing spawn
1.概述multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-s
python 多进程 multiprocessing模块 子进程 Windows