Structure the code to farm off work to dedicated threads for specific types of work.
Simulation Requirements
[x] Menu Bar for selecting and launching a simulation.
[x] Simulation launches into a nested window. The window should maximize filling the parent window's view port.
[x] A simulation window shouldn't just start doing stuff. When it launches it should open with a description of what it does and have a button "Start, Launch, Initiate, etc...". Clicking the button should have the effect of starting the simulation.
[x] When a simulation has started, a stop button should appear. It could be that the start button changes into a stop button. Clicking the stop button should pause the simulation.
[x] When a simulation's DPG window is closed it should explicitly kill all spawned threads and free up any resources.
Implementation Thoughts
The Main function needs to set everything up. Provision UI context, dedicated worker threads, etc.
Have a centralized simulation loop. Each frame needs to have a budget.
Need a way to detect dropping frames.
Development Path
Get the happy path of agents interacting using linear code.
Threads can be used to distribute work. The threading module is the high level module for working with threads.
The queue module provides thread safe queues for moving items between threads. There are FIFO, LIFO, and Priority queues.
Threads are not parallel processing. They leverage context switching. In CPython, due to the Global Interpreter Lock (GIL), only one thread can execute Python code at once. Threads are ideal for I/O bound use cases (e.g. writing to disk, network requests).
The multiprocessing module provides parallel processing for multi-core/processor machines. This modules uses sub-processes rather than threading. Threads remain within a single process.
Each process has its own dedicated Python Interpreter.
You use the subprocess module for working with child processes.
Processes can be communicated with via Queues and Pipes.
Examples
Use Case
Structure the code to farm off work to dedicated threads for specific types of work.
Simulation Requirements
Implementation Thoughts
Development Path
GUI Considerations
GUI Setup
Python Concurrency Options
Python Concurrency
Multi-Threading
Threads can be used to distribute work. The threading module is the high level module for working with threads.
The queue module provides thread safe queues for moving items between threads. There are FIFO, LIFO, and Priority queues.
Threads are not parallel processing. They leverage context switching. In CPython, due to the Global Interpreter Lock (GIL), only one thread can execute Python code at once. Threads are ideal for I/O bound use cases (e.g. writing to disk, network requests).
Async future callables can be spawned using concurrent.futures.
The asyncio module provides async/await functionality for working with Ccroutines. Asyncio programming consideration.
Multi-Processing
The multiprocessing module provides parallel processing for multi-core/processor machines. This modules uses sub-processes rather than threading. Threads remain within a single process. Each process has its own dedicated Python Interpreter.
You use the subprocess module for working with child processes.
Processes can be communicated with via Queues and Pipes. Examples
Multiprocessing Queue Parallel Processing programming guidelines
You can share a chunk of memory across processes using the multiprocessing.shared_memory module.