'Schedule and display events until time is up'

def run(self, end_time, delay=False):

    for (_, proc) in sorted(self.procs.items()):
        first_event = next(proc)
        self.events.put(first_event)
    sim_time = 0
    while (sim_time < end_time):
        if self.events.empty():
            print '***    end    of    events    ***'
            break
        current_event = self.events.get()
        if delay:
            time.sleep(((current_event.time - sim_time) / 2))
        (sim_time, proc_id, previous_action) = current_event
        print ('taxi:', proc_id, (proc_id * '            '), current_event)
        active_proc = self.procs[proc_id]
        next_time = (sim_time + compute_duration(previous_action))
        try:
            next_event = active_proc.send(next_time)
        except StopIteration:
            del self.procs[proc_id]
        else:
            self.events.put(next_event)
    else:
        msg = '***    end    of    simulation    time:    {}    events    pending    ***'
        print msg.format(self.events.qsize())
