'Python synchronize transaction in mutually dependent concurrent tasks
I'm designing a plant simulation script in Python and need some advice on good approaches to task simulation
The plant is a box sorting and processing where different subsystems pass de box(es) to the following subsystem.
e.g:
- sys-A => single line receives boxes and selects 1 of 5 output buffers --> (sys-B)
- sys-B => the buffers can be 0 to N boxes full, at level M (M < N) a signal is raised to following subsystem (sys-C) to take de M-sized batch of boxes to process
- sys-C => has it's own cycle time. Can be busy or idle when it receives signal from a sys-B. When it starts it's cycle it takes M-size batch of boxes as input to process
I have a time-stamped stream of input boxes (historic) that I'd like to run against.
I need to get periodic status of the plant (sum of subsystems) at any given periodic historic time (say 10secs, 1minute or any amount of historic elapsed time).
Given the big amount of data to process I'm aiming to split the workload into different concurrent tasks, each task for each subsystem and provide data between them (so far no problem)
Given the different timing and conditions in the subsystems, events can trigger (or not) to the following subsystems at any intermediate point in time during the interval. So the status of a subsystem is not directly related to it's input but also to the following subsystem (e.g: the sys-B gets filled by sys-A but emptied by sys-C, however sys-C has it's own timing so there is no guarantee that a signal sent to sys-C has to be honored during the observing time period).
My challenge is how can I make sure I have processed all events across the subsystems in order to get an accurate subsystem status?
PS: Just to be clear the simulation is supposed to be fast paced and has no relation to real time elapsing, so a simple timer is not a solution.
Is there a "best practice" for ensuring synchronization in mutually dependent tasks?
Any ideas are welcome.
Best regards Alex
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
