The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several older modules and functions:
The return value can be 'fork', 'spawn', 'forkserver' or None. See Contexts and start methods. Added in version 3.4. Changed in version 3.8: On macOS, the spawn start method is now the default. The fork start method should be considered unsafe as it can lead to crashes of the subprocess. See bpo-33725.
The concurrent.futures module provides a high-level interface for asynchronously executing callables. The asynchronous execution can be performed with threads, using ThreadPoolExecutor or InterpreterPoolExecutor, or separate processes, using ProcessPoolExecutor. Each implements the same interface, which is defined by the abstract Executor class.
asyncio is a library to write concurrent code using the async/await syntax. asyncio is used as a foundation for multiple Python asynchronous frameworks that provide high-performance network and web-servers, database connection libraries, distributed task queues, etc. asyncio is often a perfect fit for IO-bound and high-level structured network code.
Executing commands quoted by this module on such shells can open up the possibility of a command injection vulnerability. Consider using functions that pass command arguments with lists such as subprocess.run() with shell=False. This idiom would be unsafe:
To avoid this issue, users of subprocess or standalone Python processes should set track to False when there is already another process in place that does the bookkeeping. track is ignored on Windows, which has its own tracking and automatically deletes shared memory when all handles to it have been closed.
Older high-level API Replacing Older Functions with the subprocess Module Replacing /bin/sh shell command substitution Replacing shell pipeline Replacing os.system() Replacing the os.spawn family Replacing os.popen() Legacy Shell Invocation Functions Notes Timeout Behavior Converting an argument sequence to a string on Windows Disable use of ...
Source code: Lib/pty.py The pty module defines operations for handling the pseudo-terminal concept: starting another process and being able to write to and read from its controlling terminal progra...