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
with
statement
multiprocessing
— Process-based parallelismmultiprocessing.shared_memory
— Shared memory for direct access across processes- The
concurrent
package concurrent.futures
— Launching parallel taskssubprocess
— Subprocess management- Using the
subprocess
Module - Security Considerations
- Popen Objects
- Windows Popen Helpers
STARTUPINFO
- Windows Constants
STD_INPUT_HANDLE
STD_OUTPUT_HANDLE
STD_ERROR_HANDLE
SW_HIDE
STARTF_USESTDHANDLES
STARTF_USESHOWWINDOW
STARTF_FORCEONFEEDBACK
STARTF_FORCEOFFFEEDBACK
CREATE_NEW_CONSOLE
CREATE_NEW_PROCESS_GROUP
ABOVE_NORMAL_PRIORITY_CLASS
BELOW_NORMAL_PRIORITY_CLASS
HIGH_PRIORITY_CLASS
IDLE_PRIORITY_CLASS
NORMAL_PRIORITY_CLASS
REALTIME_PRIORITY_CLASS
CREATE_NO_WINDOW
DETACHED_PROCESS
CREATE_DEFAULT_ERROR_MODE
CREATE_BREAKAWAY_FROM_JOB
- Older high-level API
- Replacing Older Functions with the
subprocess
Module - Legacy Shell Invocation Functions
- Notatki
- Using the
sched
— Event schedulerqueue
— A synchronized queue classcontextvars
— Context Variables
The following are support modules for some of the above services: