self.env._active_proc = None
+ """Result of a :class:`~simpy.events.Condition`. It supports convenient
+ dict-like access to the triggered events and their values. The events are
+ ordered by their occurences in the condition."""
+ def __getitem__(self, key):
+ if key not in self.events:
+ raise KeyError(str(key))
+ def __contains__(self, key):
+ return key in self.events
+ def __eq__(self, other):
+ if type(other) is ConditionValue:
+ return self.events == other.events
+ return self.todict() == other
+ return '<ConditionValue %s>' % self.todict()
+ return [event._value for event in self.events]
+ return [(event, event._value) for event in self.events]
+ return dict((event, event._value) for event in self.events)
"""An event that gets triggered once the condition function *evaluate*
returns ``True`` on the given list of *events*.
- The value of the condition event is an ordered dictionary that maps the
- input events to their respective values. It only contains entries for those
- events that occurred before the condition is processed.
+ The value of the condition event is an instance of :class:`ConditionValue`
+ which allows convenient access to the input events and their values. The
+ :class:`ConditionValue` will only contain entries for those events that
+ occurred before the condition is processed.
If one of the events fails, the condition also fails and forwards the
exception of the failing event.
- # Register a callback which will update the value of this
- # condition once it is being processed.
+ # Register a callback which will build the value of this condition
+ # after it has been triggered.
"""Return a string *Condition(evaluate, [events])*."""
return '%s(%s, %s)' % (self.__class__.__name__,
- """Recursively collect the current values of all nested conditions into
+ def _populate_value(self, value):
+ """Populate the *value* by recursively visiting all nested
for event in self._events:
if isinstance(event, Condition):
elif event.callbacks is None:
s[event ] = event._value
- def _collect_values(self, event):
- """Update the final value of this condition."""
+ def _build_value(self, event):
+ """Build the value of this condition."""
- self._value = OrderedDict()
+ self._value = ConditionValue()
"""Check if the condition was already met and schedule the *event* if