Example #1
0
    def traverse(self) -> None:
        # Invoked by crossing passengers in order to get through their luggage and body scan.
        me = local.name
        if self._num_standing == 0:
            period_empty = now() - self._moment_empty
            self._time_empty += period_empty
            debug(f"Belt {self.num} -- Empty period: {period_empty:.1f} -- Time empty: {self.time_empty:.1f}")
        self._num_standing += 1
        info(f"Traveler {me} entering belt {self.num}; now {self.num_standing} travelers here")

        # Prepare for check.
        advance(next(traveler_preparation))

        # Wait for an agent to beckon.
        info(f"Traveler {me} (belt {self.num}) prepared and ready for processing")
        self._traveler_ready.turn_on()
        self._travelers_waiting.join()

        with local.agent.using():  # Make agent busy with me.
            # Administer scan or patdown.
            agent_name = Process.current().local.agent_name
            processing_type = next(traveler_processing_type)
            info(f"Traveler {me} processed by agent {agent_name}: {processing_type}")
            advance(next(traveler_processing_time[processing_type]))

        info(f"Traveler {me} (belt {self.num}) buckling back up")
        advance(next(traveler_preparation))

        self._num_standing -= 1
        if self._num_standing == 0:
            debug(f"Belt {self.num} now empty")
            self._moment_empty = now()
Example #2
0
def service():
    global num_served
    time_start = now()
    with resource.using():
        advance(rng.expovariate(RATE_SERVICE))
    times_service.append(now() - time_start)
    num_served += 1
Example #3
0
def wait_for(signal: Signal,
             times_expected: List[float],
             delay_between: float,
             log: List[float] = []):
    for expected in times_expected:
        advance(delay_between)
        signal.wait()
        assert pytest.approx(expected) == now()
        log.append(now())
Example #4
0
def traveler():
    global traveler_name
    traveler_name += 1
    name = traveler_name

    local.name = name
    local.priority = next(traveler_priority)
    time_arrival = now()

    # Kick the agent awake so he gets me a belt.
    info(f"Traveler {name} entering checkpoint's main queue")
    traveler_enters_main_queue.turn_on()
    main_queue.join()

    # Got a belt -- traverse it.
    local.belt.traverse()

    # Leaving the belt -- kick the agent awake in case this frees up the progress of some passengers stuck in the main
    # queue.
    info(f"Traveler {name} coming out of checkpoint")
    traveler_exits_belt.turn_on()
    log_time_through_checkpoint.append(now() - time_arrival)
Example #5
0
    def filter(self, record: logging.LogRecord) -> int:
        try:
            sim_time = now()
            sim_process = local.name
        except TypeError:
            sim_time = -1.0
            sim_process = ""

        for attr, value in [
            ("sim_time", sim_time),
            ("sim_process", sim_process)
        ]:
            if not hasattr(record, attr):
                setattr(record, attr, value)

        return 1
Example #6
0
 def process(the_log):
     the_log.append(now())
Example #7
0
 def proc(delay):
     advance(delay)
     log.append(now())
     add(proc, delay * 2.0)
Example #8
0
 def last_proc():
     nonlocal when_last
     when_last = now()
Example #9
0
 def process(name, results, delay_start):
     advance(delay_start)
     for n in range(5):
         results.append((now(), name, n))
         advance(2)
Example #10
0
 def tick(name, period, log):
     while True:
         advance(period)
         log.append((int(now()), name))
Example #11
0
 def last_proc():
     nonlocal when_last
     when_last = now()
     assert Process.current().has_tag(TestTag.ALICE)
     assert Process.current().has_tag(TestTag.BOB)
Example #12
0
def sim_time():
    return [now()]
 def time_check(*args, **kwargs):
     assert delay == now()
     fn(*args, **kwargs)
 def tag_propogator(tag_set):
     sim.add_in(10, create_time_check(now() + 10, tag_checker),
                tag_set | set([IntegTestTag.CANADA]))
Example #15
0
 def waiter_turning_off(signal: Signal, log: List[float]):
     signal.wait()
     signal.turn_off()
     log.append(now())
Example #16
0
 def process(ll):
     ll.append(now())
     advance(1.0)
     ll.append(now())
     advance(5.0)
     ll.append(now())
Example #17
0
def do_while_holding_resource(delay: float, log: List[float]):
    advance(delay)
    log.append(now())
Example #18
0
 def proc():
     nonlocal num
     log.append(now())
     num += 1
     if num >= 5:
         stop()