simpy.core — SimPy’s core components

Core components for event-discrete simulation environments.

class simpy.core.BaseEnvironment

Base class for event processing environments.

An implementation must at least provide the means to access the current time of the environment (see now) and to schedule (see schedule()) events as well as processing them (see step().

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.

There are two default priority values, URGENT and NORMAL.

step()

Processes 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 when 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. Raises a RuntimeError if there are no further events to be processed and the until event was not triggered.
  • If it is a number, the method will continue stepping until the environment’s time reaches until.
exit(value=None)

Stop the current process, optionally providing a value.

This is a convenience function provided for Python versions prior to 3.3. From Python 3.3, you can instead use return value in a process.

class simpy.core.Environment(initial_time=0)

Execution environment for an event-based simulation. The passing of time is simulated by stepping from event to event.

You can provide an initial_time for the environment. By default, 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.

process(generator)

Create a new Process instance for generator.

timeout(delay, value=None)

Return a new Timeout event with a delay and, optionally, a value.

event()

Return a new Event instance. Yielding this event suspends a process until another process triggers the event.

all_of(events)

Return a new AllOf condition for a list of events.

any_of(events)

Return a new AnyOf condition for a list of events.

exit(value=None)

Stop the current process, optionally providing a value.

This is a convenience function provided for Python versions prior to 3.3. From Python 3.3, you can instead use return value in a process.

schedule(event, priority=1, delay=0)

Schedule an event with a given priority and a delay.

peek()

Get the time of the next scheduled event. Return Infinity if there is no further event.

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 when 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. Raises a RuntimeError if there are no further events to be processed and the until event was not triggered.
  • If it is 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 an Environment if there are no further events to be processed.

simpy.core.Infinity = inf

Convenience alias for infinity

Read the Docs v: latest
Versions
latest
stable
3.0.7
3.0.6
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0
Downloads
pdf
htmlzip
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.