問題描述
我的工作應該使用并行技術,我是 python 的新用戶.所以我想知道你是否可以分享一些關于 python multiprocessing
和 subprocess
模塊的材料.這兩者有什么區別?
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.
這篇關于多進程和子進程有什么區別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!