A process is a running application with its own memory space, inaccessible to other applications. Multiple processes can run on one machine; multicore CPUs may execute them simultaneously, while single-core systems use operating-system time slicing. section 1.4.1
Processes are operating-system units of concurrency. They can handle I/O-bound or CPU-bound work, while asyncio usually uses a single thread and non-blocking I/O to coordinate many waiting tasks. section 1.8
Related process models clarify where memory, execution, and control live:
- Threads are lighter-weight units associated with a process and share its memory; every process has at least a main thread. section 1.4.2
- Multiprocessing creates parent and child processes, allowing Python functions to run in parallel and helping CPU-bound work bypass the global interpreter lock. section 6.0
- An asyncio subprocess is represented by a Process object returned from create_subprocess_exec or create_subprocess_shell. section 13.1
Running and stopping an asynchronous subprocess
Create a command with create_subprocess_exec, inspect its pid, and await process.wait() for its exit status. If waiting exceeds a one-second timeout, call process.terminate() and await completion again. Prefer the exec form unless shell functionality is required, because shell behavior can vary between machines. section 13.1
Process communication depends on the subprocess interface. communicate can send input and wait for termination; interactive programs require concurrent StreamReader and StreamWriter use through stdout and stdin pipes. section 13.2
