simpy.core — SimPy’s core components¶
This module contains the implementation of SimPy’s core classes. The most important ones are directly importable via simpy.
- class simpy.core.BaseEnvironment¶
The abstract definition of an environment.
An implementation must at least provide the means to access the current time of the environment (see now) and to schedule (see schedule()) as well as execute (see step() and run()) events.
The class is meant to be subclassed for different execution environments. For example, SimPy defines a Environment for simulations with a virtual time and and a RealtimeEnvironment that schedules and executes events in real (e.g., wallclock) time.
- now¶
The current time of the environment.
- active_process¶
The currently active process of the environment.
- schedule(event, priority=1, delay=0)¶
Schedule an event with a given priority and a delay.
- step()¶
Process the next event.
- run(until=None)¶
Executes step() until the given criterion until is met.
- If it is None (which is the default) this method will return if there are no further events to be processed.
- If it is an Event the method will continue stepping until this event has been triggered and will return its value.
- If it can be converted to a number the method will continue stepping until the environment’s time reaches until.
- class simpy.core.Environment(initial_time=0)¶
Inherits BaseEnvironment and implements a simulation environment which simulates the passing of time by stepping from event to event.
You can provide an initial_time for the environment. By defaults, it starts at 0.
This class also provides aliases for common event types, for example process, timeout and event.
- now¶
The current simulation time.
- active_process¶
The currently active process of the environment.
- event()¶
Return a new Event instance. Yielding this event suspends a process until another process triggers the event.
- exit(value=None)¶
Convenience function provided for Python versions prior to 3.3. Stop the current process, optionally providing a value.
Note
From Python 3.3, you can use return value instead.
- schedule(event, priority=1, delay=0)¶
Schedule an event with a given priority and a delay.
- step()¶
Process the next event.
Raise an EmptySchedule if no further events are available.
- run(until=None)¶
Executes step() until the given criterion until is met.
- If it is None (which is the default) this method will return if there are no further events to be processed.
- If it is an Event the method will continue stepping until this event has been triggered and will return its value.
- If it can be converted to a number the method will continue stepping until the environment’s time reaches until.
- class simpy.core.BoundClass(cls)¶
Allows classes to behave like methods.
The __get__() descriptor is basically identical to function.__get__() and binds the first argument of the cls to the descriptor instance.
- static bind_early(instance)¶
Bind all BoundClass attributes of the instance’s class to the instance itself to increase performance.
- class simpy.core.EmptySchedule¶
Thrown by the Environment if there are no further events to be processed.
- simpy.core.Infinity = inf¶
Convenience alias for infinity