多重处理和子流程有什么区别? [英] What is the difference between multiprocessing and subprocess?

查看:80
本文介绍了多重处理和子流程有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作应该使用并行技术,并且我是python的新用户.因此,我想知道您是否可以共享有关python multiprocessingsubprocess模块的一些资料.两者有什么区别?

My work should use parallel techniques, and I a new user of python. So I wonder if you could share some material about the python multiprocessing and subprocess modules. What is the difference between these two?

推荐答案

subprocess模块可让您运行和控制其他程序.您可以使用计算机上的命令行启动的任何内容,都可以使用此模块运行和控制.使用它可以将外部程序集成到您的Python代码中.

The subprocess module lets you run and control other programs. Anything you can start with the command line on the computer, can be run and controlled with this module. Use this to integrate external programs into your Python code.

multiprocessing模块可让您将用python编写的任务划分为多个进程,以帮助提高性能.它提供了与threading模块非常相似的API.它提供了在创建的进程之间共享数据的方法,并使管理多个进程以运行Python代码的任务更加容易.换句话说,multiprocessing使您可以利用多个进程通过并行执行代码来更快地完成任务.

The multiprocessing module lets you divide tasks written in python over multiple processes to help improve performance. It provides an API very similar to the threading module; it provides methods to share data across the processes it creates, and makes the task of managing multiple processes to run Python code (much) easier. In other words, multiprocessing lets you take advantage of multiple processes to get your tasks done faster by executing code in parallel.

这篇关于多重处理和子流程有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆