Producer-consumer class. Responsible for initializing producers and consumers and controlling execution.
Initializes Calculon.
Keyword arguments
Starts producer and consumer threads / processes and controls the execution.
Keyword arguments
None
Returns a dictionary containing two elements:
Producer class.
Producer superclass, contains all of the functionality. Calculon does not deal with this class directly, rather it instantiates ProducerThread or ProducerProcess that inherit from _Producer and from either Thread or Process classes.
Keyword arguments
Runs the producer function once.
Keyword arguments
None
When the producer function is called, two additional arguments are passed to it:
Returns
If the run completed successfully, the method returns a dictionary with two keys:
- “name” – name of this producer (uuid);
- “result” – the return value returned from the producer function.
If the run completed unsuccessfully, the method returns a dictionary with two keys:
- “name” – name of this producer (uuid);
- “exception” – the exception object for the raised exception.
Consumer class.
Consumer superclass, contains all of the functionality. Calculon does not deal with this class directly, rather it instantiates ConsumerThread or ConsumerProcess that inherit from _Consumer and from either Thread or Process classes.
Keyword arguments
Runs the producer function once.
Keyword arguments
None
Consumer will repeteadly try to get a value from the queue until all producers have shutdown and the queue is not empty. Each time it succeeds, the value is passed to the consumer function to process the value. Once there are no more values in the queue and all of the producers have stopped, each of the consumers will be called once more, to allow to perform any sort of cleanup that might be required.
Along with each call to the consumer function, the following values are passed in the argument dictionary.
Sets the exit flag. The exit flag is used by the run() code to check if the consumer can be shutdown safely. It is called from the Calculon instance and indicates that all of the producers have stopped running.
Instantiates _Consumer and Thread superclasses.
Instantiates _Consumer and Process superclasses.