2022-04-11 - Python multiprocessing subprocess 模块区别

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2022-04-11 - Python multiprocessing subprocess 模块区别相关的知识,希望对你有一定的参考价值。

参考技术A

multiprocessing和subprocess都是对操作系统底层多进程api的封装:

multiprocessing:

subprocess:

multiprocessing创造的进程 必须用于执行若干个(若干段)python脚本 ,它 完全类似threading模块,只是是进程级别的
subprocess则创造了简单的普通进程,并提供了完整的与输入、输出、错误流交互的api,可以获取进程的返回码

使用multiprocessing:

使用subprocess:

python 列出具有multi和sum.py的压缩



def compress_list_multi(list): #multiplies the first half of a list by the indexes in the second half.
	midpoint = (len(list) / 2)
	one, two = list[0:midpoint], list[midpoint:len(list)]
	return [one[i]*two[i] for i in range(len(one))]
def compress_list_sum(list):
	midpoint = (len(list) / 2)
	one, two = list[0:midpoint], list[midpoint:len(list)]
	return [one[i]+two[i] for i in range(len(one))]
def compress_all_multi(list): #reduces a list to a single entry by multiplying all items.
	while len(list) > 1:
		midpoint = (len(list) / 2)
		one, two = list[0:midpoint], list[midpoint:len(list)]
		list = [one[i]*two[i] for i in range(len(one))]
	return list
def compress_all_sum(list): #reduces a list to a single enty by adding all items. 
	while len(list) > 1:
		midpoint = (len(list) / 2)
		one, two = list[0:midpoint], list[midpoint:len(list)]
		list = [one[i]+two[i] for i in range(len(one))]
	return list
	
	

以上是关于2022-04-11 - Python multiprocessing subprocess 模块区别的主要内容,如果未能解决你的问题,请参考以下文章

python multi process multi thread

Mediapipe 手 python 结果没有 multi_hand_world_landmarks

python实现累乘multi函数(函数参数不限)

python reuters_multi_cnn.py

python 列出具有multi和sum.py的压缩

python multi_index.from_list