Concurrent Execution¶
The modules described in this chapter provide support for concurrent execution of code. The appropriate choice of tool will depend on the task to be executed (CPU bound vs IO bound) and preferred style of development (event driven cooperative multitasking vs preemptive multitasking). Here’s an overview:
threading— Thread-based parallelismactive_count()current_thread()excepthook()__excepthook__get_ident()get_native_id()enumerate()main_thread()settrace()settrace_all_threads()gettrace()setprofile()setprofile_all_threads()getprofile()stack_size()TIMEOUT_MAX- Thread-Local Data
- Thread Objects
- Lock Objects
- RLock Objects
- Condition Objects
- Semaphore Objects
- Event Objects
- Timer Objects
- Barrier Objects
- Using locks, conditions, and semaphores in the
withstatement
multiprocessing— Process-based parallelismmultiprocessing.shared_memory— Shared memory for direct access across processes- The
concurrentpackage concurrent.futures— Launching parallel taskssubprocess— Subprocess management- Using the
subprocessModule - Security Considerations
- Popen Objects
- Windows Popen Helpers
STARTUPINFO- Windows Constants
STD_INPUT_HANDLESTD_OUTPUT_HANDLESTD_ERROR_HANDLESW_HIDESTARTF_USESTDHANDLESSTARTF_USESHOWWINDOWSTARTF_FORCEONFEEDBACKSTARTF_FORCEOFFFEEDBACKCREATE_NEW_CONSOLECREATE_NEW_PROCESS_GROUPABOVE_NORMAL_PRIORITY_CLASSBELOW_NORMAL_PRIORITY_CLASSHIGH_PRIORITY_CLASSIDLE_PRIORITY_CLASSNORMAL_PRIORITY_CLASSREALTIME_PRIORITY_CLASSCREATE_NO_WINDOWDETACHED_PROCESSCREATE_DEFAULT_ERROR_MODECREATE_BREAKAWAY_FROM_JOB
- Older high-level API
- Replacing Older Functions with the
subprocessModule - Legacy Shell Invocation Functions
- Notes
- Using the
sched— Event schedulerqueue— A synchronized queue classcontextvars— Context Variables
The following are support modules for some of the above services: