首页 > python > 为什么Python的子进程模块会调用它而不仅仅是'进程'?

为什么Python的子进程模块会调用它而不仅仅是'进程'? (Why is Python's subprocess module called that and not just 'process'?)

2018-12-18 pythonsubprocess

问题

我是线程和流程的新手。我一直在努力理解asyncio。研究asyncio并发的周节的道格·海林格的Python模块,我跑进multiprocessingthreadingsignalsubprocess模块。

我一直想知道为什么这个名字subprocess模块被命名了。为什么模块没有被称为进程。关于它的'sub'是什么意思?

编辑:忘记添加

有一个Popen班级,我认为'P'代表过程。在Github的代码评论说:

Popen(...):用于在新进程中灵活执行命令的类

不存在Popen类,给出更多理由来调用模块process而不是subprocess

解决方法

大多数操作系统中的进程形成父子关系。由另一个进程创建的进程称为该进程的子进程或子进程:

子进程中计算是通过另一过程(父进程)产生的过程。此技术适用于多任务操作系统,有时称为子进程或传统的子任务

Python 进程模块提供了创建新子进程的工具(即使用此模块创建的每个进程都将是Python程序的子进程):

进程模块允许您生成新进程,连接到它们的输入/输出/错误管道,并获取它们的返回代码。

它不处理任意进程,因此命名它subprocess而不仅仅是有意义process

问题

I am new to threading and processes. I have been trying to understand asyncio. Researching asyncio on Doug Hellinger's Python Module of the Week section of Concurrency, I ran into the multiprocessing, threading, signal and subprocess modules.

I have been wondering why the name subprocess module was named thus. Why is the module not called process. And what is 'sub' [meaning below] about it?

Edit: Forgotten addition

There's a Popen class and I assume the 'P' stands for process. The Github code comment says:

Popen(...): A class for flexibly executing a command in a new process

Doesn't the existence of the Popen class, give more reason to call the module process instead of subprocess?

解决方法

Processes in most operating systems form a parent-child relationship. Processes created by another process are called child processes or subprocesses of that process:

A child process in computing is a process created by another process (the parent process). This technique pertains to multitasking operating systems, and is sometimes called a subprocess or traditionally a subtask.

Python subprocess module provides facilities to create new child processes (i.e. every process created with this module will be subprocess of your Python program):

The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.

It does not deal with arbitrary processes, so it makes sense to name it subprocess instead of just process.

相似信息