This events module contains the various event type used by the SimPy core.
The base class for all events is Event. Though it can be directly used, there are several specialized subclasses of it:
This module also defines the Interrupt exception.
Unique object to identify pending values of events.
Priority of interrupts and process initialization events.
Default priority used by events.
Base class for all events.
Every event is bound to an environment env (see BaseEnvironment) and has an optional value.
An event has a list of callbacks. A callback can be any callable that accepts a single argument which is the event instances the callback belongs to. This list is not exclusively for SimPy internals—you can also append custom callbacks. All callbacks are executed in the order that they were added when the event is processed.
This class also implements __and__() (&) and __or__() (|). If you concatenate two events using one of these operators, a Condition event is generated that lets you wait for both or one of them.
List of functions that are called when the event is processed.
Becomes True if the event has been triggered and its callbacks are about to be invoked.
Becomes True if the event has been processed (e.g., its callbacks have been invoked).
The value of the event if it is available.
The value is available when the event has been triggered.
Raise a AttributeError if the value is not yet available.
Triggers the event with the state and value of the provided event.
This method can be used directly as a callback function.
Schedule the event and mark it as successful. Return the event instance.
You can optionally pass an arbitrary value that will be sent into processes waiting for that event.
Raise a RuntimeError if this event has already been scheduled.
An Event that is scheduled with a certain delay after its creation.
This event can be used by processes to wait (or hold their state) for delay time steps. It is immediately scheduled at env.now + delay and has thus (in contrast to Event) no success() or fail() method.
Initializes a process. Only used internally by Process.
A Process is a wrapper for the process generator (that is returned by a process function) during its execution.
It also contains internal and external status information and is used for process interaction, e.g., for interrupts.
Process inherits Event. You can thus wait for the termination of a process by simply yielding it from your process function.
An instance of this class is returned by simpy.core.Environment.process().
The event that the process is currently waiting for.
May be None if the process was just started or interrupted and did not yet yield a new event.
True until the process generator exits.
A Condition Event groups several events and is triggered if a given condition (implemented by the evaluate function) becomes true.
The value of the condition is a dictionary that maps the input events to their respective values. It only contains entries for those events that occurred until the condition was met.
If one of the events fails, the condition also fails and forwards the exception of the failing event.
The evaluate function receives the list of target events and the number of processed events in this list. If it returns True, the condition is scheduled. The Condition.all_events() and Condition.any_events() functions are used to implement and (&) and or (|) for events.
Conditions events can be nested.
A condition function that returns True if all events have been triggered.
A condition function that returns True if at least one of events has been triggered.
A Condition event that waits until the first of events is triggered.
This exceptions is sent into a process if it was interrupted by another process (see Process.interrupt()).
cause may be none if no cause was explicitly passed to Process.interrupt().
An interrupt has a higher priority as a normal event. Thus, if a process has a normal event and an interrupt scheduled at the same time, the interrupt will always be thrown into the process first.
If a process is interrupted multiple times at the same time, all interrupts will be thrown into the process in the same order as they occurred.
The cause of the interrupt or None if no cause was provided.