liveBook · Manning

Process

As explained in Python Concurrency with asyncio

An asyncio process is an object representing a subprocess and providing asynchronous waiting plus process-control methods.

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

How Python Concurrency with asyncio covers it

How deep it goes
Explains memory isolation, scheduling, threads, multiprocessing, subprocess control, and communication, without detailing operating-system scheduling algorithms.
Examples
Demonstrates process IDs, thread counts, child processes, directory listing, timeouts, termination, username input, and interactive echoing.
What you can do after
Operate subprocesses with asyncio, await completion, terminate timed-out work, and exchange data through standard-input and standard-output streams.
How it connects
Connects processes with threads, multiprocessing, concurrency, parallelism, asyncio, event loops, subprocesses, and the global interpreter lock.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Concurrency with asyncio. The section links point to the parts of the book it draws on.