Event

class passengersim.core.Event

Bases: object

A user event to put on the simulation’s event queue.

An Event pairs any Python object, its payload, with a time. Add it to the queue with SimulationEngine.add_event. SimulationEngine.go works through the queue in time order, processing booking events itself; when it reaches an Event it stops and returns the payload, so the caller can act on it. PassengerSim uses this for things like DCPs and daily RM callbacks.

SimulationEngine.add_event copies the payload and time when it is called, so changing the Event afterward does not change the queued event, and the same Event can be added again. Events with the same time may come back in any order. Event cannot be subclassed.

Parameters:
payload : object

Any Python object; SimulationEngine.go returns it when the event is reached.

event_time : float

When the event happens, usually a Unix timestamp; see event_time.

Raises:

TypeError – If event_time is not a real number.

Methods

__init__(*args, **kwargs)

Attributes

event_time

When the event happens, as a float.

payload

The Python object that SimulationEngine.go returns when this event is reached.

event_time

When the event happens, as a float.

The event queue is ordered by this time, earliest first, and PassengerSim uses Unix timestamps (in seconds). When SimulationEngine.go reaches the event, it also sets SimulationEngine.last_event_time to this time. Setting it accepts any real number, which is stored as a float; it cannot be deleted.

payload

The Python object that SimulationEngine.go returns when this event is reached.

It can be any object, including None. Reading it raises AttributeError if it has been deleted, or if the Event was created without calling __init__; SimulationEngine.add_event raises ValueError for an Event in that state.