back to Claude Sonnet 3.5 - Base summary
Claude Sonnet 3.5 - Base: simpy
Pytest Summary for test tests
status | count |
---|---|
failed | 120 |
passed | 20 |
total | 140 |
collected | 150 |
deselected | 10 |
Failed pytests:
test_condition.py::test_operator_and
test_condition.py::test_operator_and
env =def test_operator_and(env): def process(env): timeout = [env.timeout(delay, value=delay) for delay in range(3)] results = yield timeout[0] & timeout[1] & timeout[2] assert results == { timeout[0]: 0, timeout[1]: 1, timeout[2]: 2, } env.process(process(env)) > env.run() tests/test_condition.py:16: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_operator_and_blocked
test_condition.py::test_operator_and_blocked
env =def test_operator_and_blocked(env): def process(env): timeout = env.timeout(1) event = env.event() yield env.timeout(1) condition = timeout & event assert not condition.triggered env.process(process(env)) > env.run() tests/test_condition.py:29: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_operator_or
test_condition.py::test_operator_or
env =def test_operator_or(env): def process(env): timeout = [env.timeout(delay, value=delay) for delay in range(3)] results = yield timeout[0] | timeout[1] | timeout[2] assert results == { timeout[0]: 0, } env.process(process(env)) > env.run() tests/test_condition.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_operator_nested_and
test_condition.py::test_operator_nested_and
env =def test_operator_nested_and(env): def process(env): timeout = [env.timeout(delay, value=delay) for delay in range(3)] results = yield (timeout[0] & timeout[2]) | timeout[1] assert results == { timeout[0]: 0, timeout[1]: 1, } assert env.now == 1 env.process(process(env)) > env.run() tests/test_condition.py:57: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_operator_nested_or
test_condition.py::test_operator_nested_or
env =def test_operator_nested_or(env): def process(env): timeout = [env.timeout(delay, value=delay) for delay in range(3)] results = yield (timeout[0] | timeout[1]) & timeout[2] assert results == { timeout[0]: 0, timeout[1]: 1, timeout[2]: 2, } assert env.now == 2 env.process(process(env)) > env.run() tests/test_condition.py:73: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_nested_cond_with_error
test_condition.py::test_nested_cond_with_error
env =def test_nested_cond_with_error(env): def explode(env): yield env.timeout(1) raise ValueError('Onoes!') def process(env): with pytest.raises(ValueError, match='Onoes!'): yield env.process(explode(env)) & env.timeout(1) env.process(process(env)) > env.run() tests/test_condition.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_cond_with_error
test_condition.py::test_cond_with_error
env =def test_cond_with_error(env): def explode(env, delay): yield env.timeout(delay) raise ValueError(f'Onoes, failed after {delay}!') def process(env): with pytest.raises(ValueError, match='Onoes, failed after 0!'): yield env.process(explode(env, 0)) | env.timeout(1) env.process(process(env)) > env.run() tests/test_condition.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_cond_with_nested_error
test_condition.py::test_cond_with_nested_error
env =def test_cond_with_nested_error(env): def explode(env, delay): yield env.timeout(delay) raise ValueError(f'Onoes, failed after {delay}!') def process(env): with pytest.raises(ValueError, match='Onoes, failed after 0!'): yield env.process(explode(env, 0)) & env.timeout(1) | env.timeout(1) env.process(process(env)) > env.run() tests/test_condition.py:112: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_cond_with_uncaught_error
test_condition.py::test_cond_with_uncaught_error
env =def test_cond_with_uncaught_error(env): """Errors that happen after the condition has been triggered will not be handled by the condition and cause the simulation to crash.""" def explode(env, delay): yield env.timeout(delay) raise ValueError(f'Onoes, failed after {delay}!') def process(env): yield env.timeout(1) | env.process(explode(env, 2)) env.process(process(env)) with pytest.raises(ValueError, match='Onoes, failed after'): > env.run() tests/test_condition.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_iand_with_and_cond
test_condition.py::test_iand_with_and_cond
env =def test_iand_with_and_cond(env): def process(env): cond = env.timeout(1, value=1) & env.timeout(2, value=2) orig = cond cond &= env.timeout(0, value=0) assert cond is not orig results = yield cond assert list(results.values()) == [1, 2, 0] env.process(process(env)) > env.run() tests/test_condition.py:144: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_iand_with_or_cond
test_condition.py::test_iand_with_or_cond
env =def test_iand_with_or_cond(env): def process(env): cond = env.timeout(1, value=1) | env.timeout(2, value=2) orig = cond cond &= env.timeout(0, value=0) assert cond is not orig results = yield cond assert list(results.values()) == [1, 0] env.process(process(env)) > env.run() tests/test_condition.py:159: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_ior_with_or_cond
test_condition.py::test_ior_with_or_cond
env =def test_ior_with_or_cond(env): def process(env): cond = env.timeout(1, value=1) | env.timeout(2, value=2) orig = cond cond |= env.timeout(0, value=0) assert cond is not orig results = yield cond assert list(results.values()) == [0] env.process(process(env)) > env.run() tests/test_condition.py:174: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_ior_with_and_cond
test_condition.py::test_ior_with_and_cond
env =def test_ior_with_and_cond(env): def process(env): cond = env.timeout(1, value=1) & env.timeout(2, value=2) orig = cond cond |= env.timeout(0, value=0) assert cond is not orig results = yield cond assert list(results.values()) == [0] env.process(process(env)) > env.run() tests/test_condition.py:189: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_immutable_results
test_condition.py::test_immutable_results
env =def test_immutable_results(env): """Results of conditions should not change after they have been triggered.""" def process(env): timeout = [env.timeout(delay, value=delay) for delay in range(3)] # The or condition in this expression will trigger immediately. The and # condition will trigger later on. condition = timeout[0] | (timeout[1] & timeout[2]) results = yield condition assert results == {timeout[0]: 0} # Make sure that the results of condition were frozen. The results of # the nested and condition do not become visible afterwards. yield env.timeout(2) assert results == {timeout[0]: 0} env.process(process(env)) > env.run() tests/test_condition.py:211: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_shared_and_condition
test_condition.py::test_shared_and_condition
env =def test_shared_and_condition(env): timeout = [env.timeout(delay, value=delay) for delay in range(3)] c1 = timeout[0] & timeout[1] c2 = c1 & timeout[2] def p1(_, condition): results = yield condition assert results == {timeout[0]: 0, timeout[1]: 1} def p2(_, condition): results = yield condition assert results == {timeout[0]: 0, timeout[1]: 1, timeout[2]: 2} env.process(p1(env, c1)) env.process(p2(env, c2)) > env.run() tests/test_condition.py:229: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_shared_or_condition
test_condition.py::test_shared_or_condition
env =def test_shared_or_condition(env): timeout = [env.timeout(delay, value=delay) for delay in range(3)] c1 = timeout[0] | timeout[1] c2 = c1 | timeout[2] def p1(_, condition): results = yield condition assert results == {timeout[0]: 0} def p2(_, condition): results = yield condition assert results == {timeout[0]: 0} env.process(p1(env, c1)) env.process(p2(env, c2)) > env.run() tests/test_condition.py:247: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_condition_value
test_condition.py::test_condition_value
env =def test_condition_value(env): """The value of a condition behaves like a readonly dictionary.""" timeouts = [env.timeout(delay, value=delay) for delay in range(3)] def p(env, timeouts): results = yield env.all_of(timeouts) assert list(results) == timeouts assert list(results.keys()) == timeouts assert list(results.values()) == [0, 1, 2] assert list(results.items()) == list(zip(timeouts, [0, 1, 2])) assert timeouts[0] in results assert results[timeouts[0]] == 0 assert results == results # noqa: PLR0124 assert results == results.todict() env.process(p(env, timeouts)) > env.run() tests/test_condition.py:266: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_result_order
test_condition.py::test_result_order
env =def test_result_order(env): """The order of a conditions result is based on the order in which the events have been specified.""" timeouts = list(reversed([env.timeout(delay) for delay in range(3)])) def p(env, timeouts): results = yield env.all_of(timeouts) assert list(results.keys()) == timeouts env.process(p(env, timeouts)) > env.run() tests/test_condition.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_condition.py::test_nested_result_order
test_condition.py::test_nested_result_order
env =def test_nested_result_order(env): """The order of a conditions result is based on the order in which the events have been specified (even if nested).""" timeouts = [env.timeout(delay) for delay in range(3)] condition = (timeouts[0] | timeouts[1]) & timeouts[2] def p(_, timeouts): results = yield condition assert list(results.keys()) == timeouts env.process(p(env, timeouts)) > env.run() tests/test_condition.py:293: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_environment.py::test_event_queue_empty
test_environment.py::test_event_queue_empty
env =, log = [] def test_event_queue_empty(env, log): """The simulation should stop if there are no more events, that means, no more active process.""" def pem(env, log): while env.now < 2: log.append(env.now) yield env.timeout(1) env.process(pem(env, log)) > env.run(10) tests/test_environment.py:19: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_environment.py::test_run_negative_until
test_environment.py::test_run_negative_until
env =def test_run_negative_until(env): """Test passing a negative time to run.""" > with pytest.raises( ValueError, match='must be greater than the current simulation time' ): E Failed: DID NOT RAISE tests/test_environment.py:26: Failed
test_environment.py::test_run_resume
test_environment.py::test_run_resume
env =def test_run_resume(env): """Stopped simulation can be resumed.""" events = [env.timeout(t) for t in (5, 10, 15)] assert env.now == 0 assert not any(event.processed for event in events) > env.run(until=10) tests/test_environment.py:39: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Timeout' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_environment.py::test_run_until_value
test_environment.py::test_run_until_value
env =def test_run_until_value(env): """Anything that can be converted to a float is a valid until value.""" > env.run(until='3.141592') tests/test_environment.py:56: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , until = '3.141592' def run(self, until: Optional[Union[SimTime, Event]]=None) ->Optional[Any]: """Executes :meth:`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 :class:`~simpy.events.Event`, the method will continue stepping until this event has been triggered and will return its value. Raises a :exc:`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*. """ if until is None: while True: try: self.step() except EmptySchedule: return None elif isinstance(until, Event): until.callbacks.append(StopSimulation.callback) try: while not until.triggered: self.step() except StopSimulation: return until.value except EmptySchedule: if not until.triggered: raise RuntimeError('No scheduled events left but "until" event was not triggered') elif isinstance(until, (int, float)): try: while self._now < until: self.step() except EmptySchedule: return None else: > raise ValueError('Invalid until parameter type') E ValueError: Invalid until parameter type src/simpy/core.py:196: ValueError
test_environment.py::test_run_with_processed_event
test_environment.py::test_run_with_processed_event
env =def test_run_with_processed_event(env): """An already processed event may also be passed as until value.""" timeout = env.timeout(1, value='spam') > assert env.run(until=timeout) == 'spam' E AssertionError: assert None == 'spam' E + where None = run(until= ) E + where run = .run tests/test_environment.py:63: AssertionError
test_environment.py::test_run_with_untriggered_event
test_environment.py::test_run_with_untriggered_event
env =def test_run_with_untriggered_event(env): excinfo = pytest.raises(RuntimeError, env.run, until=env.event()) > assert str(excinfo.value).startswith( 'No scheduled events left but "until" event was not triggered:' ) E assert False E + where False = ('No scheduled events left but "until" event was not triggered:') E + where = 'No scheduled events left but "until" event was not triggered'.startswith E + where 'No scheduled events left but "until" event was not triggered' = str(RuntimeError('No scheduled events left but "until" event was not triggered')) E + where RuntimeError('No scheduled events left but "until" event was not triggered') = .value tests/test_environment.py:75: AssertionError
test_event.py::test_succeed
test_event.py::test_succeed
env =def test_succeed(env): """Test for the Environment.event() helper function.""" def child(env, event): value = yield event assert value == 'ohai' assert env.now == 5 def parent(env): event = env.event() env.process(child(env, event)) yield env.timeout(5) event.succeed('ohai') env.process(parent(env)) > env.run() tests/test_event.py:26: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_event.py::test_fail
test_event.py::test_fail
env =def test_fail(env): """Test for the Environment.event() helper function.""" def child(env, event): with pytest.raises(ValueError, match='ohai'): yield event assert env.now == 5 def parent(env): event = env.event() env.process(child(env, event)) yield env.timeout(5) event.fail(ValueError('ohai')) env.process(parent(env)) > env.run() tests/test_event.py:44: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_event.py::test_value
test_event.py::test_value
env =def test_value(env): """After an event has been triggered, its value becomes accessible.""" event = env.timeout(0, 'I am the value') > env.run() tests/test_event.py:72: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Timeout' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_event.py::test_unavailable_value
test_event.py::test_unavailable_value
env =def test_unavailable_value(env): """If an event has not yet been triggered, its value is not available and trying to access it will result in a AttributeError.""" event = env.event() with pytest.raises(AttributeError, match='.* is not yet available$'): > _ = event.value tests/test_event.py:83: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = @property def value(self) ->Optional[Any]: """The value of the event if it is available. The value is available when the event has been triggered. Raises :exc:`AttributeError` if the value is not yet available. """ if self._value is PENDING: > raise AttributeError('Value not yet available') E AttributeError: Value not yet available. Did you mean: '_value'? src/simpy/events.py:132: AttributeError During handling of the above exception, another exception occurred: env = def test_unavailable_value(env): """If an event has not yet been triggered, its value is not available and trying to access it will result in a AttributeError.""" event = env.event() > with pytest.raises(AttributeError, match='.* is not yet available$'): E AssertionError: Regex pattern did not match. E Regex: '.* is not yet available$' E Input: 'Value not yet available' tests/test_event.py:82: AssertionError
test_event.py::test_triggered
test_event.py::test_triggered
env =def test_triggered(env): def pem(env, event): value = yield event return value event = env.event() event.succeed('i was already done') > result = env.run(env.process(pem(env, event))) tests/test_event.py:94: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:183: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_event.py::test_condition_callback_removal
test_event.py::test_condition_callback_removal
env =def test_condition_callback_removal(env): """A condition will remove all outstanding callbacks from its events.""" a, b = env.event(), env.event() a.succeed() > env.run(until=a | b) tests/test_event.py:116: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:183: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Event' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_event.py::test_condition_nested_callback_removal
test_event.py::test_condition_nested_callback_removal
env =def test_condition_nested_callback_removal(env): """A condition will remove all outstanding callbacks from its events (even if nested).""" a, b, c = env.event(), env.event(), env.event() b_and_c = b & c a_or_b_and_c = a | b_and_c a.succeed() > env.run(until=a_or_b_and_c) tests/test_event.py:129: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:183: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Event' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_exceptions.py::test_error_forwarding
test_exceptions.py::test_error_forwarding
env =def test_error_forwarding(env): """Exceptions are forwarded from child to parent processes if there are any. """ def child(env): raise ValueError('Onoes!') yield env.timeout(1) def parent(env): with pytest.raises(ValueError, match='Onoes!'): yield env.process(child(env)) env.process(parent(env)) > env.run() tests/test_exceptions.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_exceptions.py::test_no_parent_process
test_exceptions.py::test_no_parent_process
env =def test_no_parent_process(env): """Exceptions should be normally raised if there are no processes waiting for the one that raises something. """ def child(env): raise ValueError('Onoes!') yield env.timeout(1) def parent(env): try: env.process(child(env)) yield env.timeout(1) except Exception as err: pytest.fail(f'There should be no error ({err}).') env.process(parent(env)) with pytest.raises(ValueError, match='Onoes!'): > env.run() tests/test_exceptions.py:50: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_exceptions.py::test_crashing_child_traceback
test_exceptions.py::test_crashing_child_traceback
env =def test_crashing_child_traceback(env): def panic(env): yield env.timeout(1) raise RuntimeError('Oh noes, roflcopter incoming... BOOM!') def root(env): try: yield env.process(panic(env)) pytest.fail("Hey, where's the roflcopter?") except RuntimeError: # The current frame must be visible in the stacktrace. stacktrace = traceback.format_exc() assert 'yield env.process(panic(env))' in stacktrace assert "raise RuntimeError('Oh noes," in stacktrace env.process(root(env)) > env.run() tests/test_exceptions.py:69: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_exceptions.py::test_exception_chaining
test_exceptions.py::test_exception_chaining
env =def test_exception_chaining(env): """Unhandled exceptions pass through the entire event stack. This must be visible in the stacktrace of the exception. """ def child(env): yield env.timeout(1) raise RuntimeError('foo') def parent(env): child_proc = env.process(child(env)) yield child_proc def grandparent(env): parent_proc = env.process(parent(env)) yield parent_proc env.process(grandparent(env)) try: > env.run() tests/test_exceptions.py:92: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_exceptions.py::test_invalid_event
test_exceptions.py::test_invalid_event
env =def test_invalid_event(env): """Invalid yield values will cause the simulation to fail.""" def root(_): yield None env.process(root(env)) with pytest.raises(RuntimeError, match='Invalid yield value "None"'): > env.run() tests/test_exceptions.py:151: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_exceptions.py::test_exception_handling
test_exceptions.py::test_exception_handling
env =def test_exception_handling(env): """If failed events are not defused (which is the default) the simulation crashes.""" event = env.event() event.fail(RuntimeError()) with pytest.raises(RuntimeError): > env.run(until=1) tests/test_exceptions.py:161: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Event' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_exceptions.py::test_callback_exception_handling
test_exceptions.py::test_callback_exception_handling
env =def test_callback_exception_handling(env): """Callbacks of events may handle exception by setting the ``defused`` attribute of ``event`` to ``True``.""" def callback(event): event.defused = True event = env.event() event.callbacks.append(callback) event.fail(RuntimeError()) assert not event.defused, 'Event has been defused immediately' > env.run(until=1) tests/test_exceptions.py:175: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Event' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_exceptions.py::test_process_exception_handling
test_exceptions.py::test_process_exception_handling
env =def test_process_exception_handling(env): """Processes can't ignore failed events and auto-handle exceptions.""" def pem(_, event): try: yield event pytest.fail('Hey, the event should fail!') except RuntimeError: pass event = env.event() env.process(pem(env, event)) event.fail(RuntimeError()) assert not event.defused, 'Event has been defused immediately' > env.run(until=1) tests/test_exceptions.py:194: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_exceptions.py::test_process_exception_chaining
test_exceptions.py::test_process_exception_chaining
env =def test_process_exception_chaining(env): """Because multiple processes can be waiting for an event, exceptions of failed events are copied before being thrown into a process. Otherwise, the traceback of the exception gets modified by a process. See https://bitbucket.org/simpy/simpy/issue/60 for more details.""" import traceback def process_a(event): try: yield event except RuntimeError: stacktrace = traceback.format_exc() assert 'process_b' not in stacktrace def process_b(event): try: yield event except RuntimeError: stacktrace = traceback.format_exc() assert 'process_a' not in stacktrace event = env.event() event.fail(RuntimeError('foo')) env.process(process_a(event)) env.process(process_b(event)) > env.run() tests/test_exceptions.py:226: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_exceptions.py::test_sys_excepthook
test_exceptions.py::test_sys_excepthook
env =def test_sys_excepthook(env): """Check that the default exception hook reports exception chains.""" def process_a(event): yield event def process_b(event): yield event event = env.event() event.fail(RuntimeError('foo')) env.process(process_b(env.process(process_a(event)))) try: > env.run() tests/test_exceptions.py:244: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError During handling of the above exception, another exception occurred: env = def test_sys_excepthook(env): """Check that the default exception hook reports exception chains.""" def process_a(event): yield event def process_b(event): yield event event = env.event() event.fail(RuntimeError('foo')) env.process(process_b(env.process(process_a(event)))) try: env.run() except BaseException: # Let the default exception hook print the traceback to the redirected # standard error channel. import sys from io import StringIO stderr, sys.stderr = sys.stderr, StringIO() typ, e, tb = sys.exc_info() assert typ is not None assert e is not None sys.excepthook(typ, e, tb) traceback = sys.stderr.getvalue() sys.stderr = stderr # Check if frames of process_a and process_b are visible in the # traceback. > assert 'process_a' in traceback E assert 'process_a' in 'Traceback (most recent call last):\n File "/testbed/tests/test_exceptions.py", line 244, in test_sys_excepthook\n ..._callback(event)\nAttributeError: \'Initialize\' object has no attribute \'_callback\'. Did you mean: \'callbacks\'?\n' tests/test_exceptions.py:264: AssertionError
test_interrupts.py::test_interruption
test_interrupts.py::test_interruption
env =def test_interruption(env): """Processes can be interrupted while waiting for other events.""" def interruptee(env): with pytest.raises(simpy.Interrupt, match='interrupt!'): yield env.timeout(10) def interruptor(env): child_process = env.process(interruptee(env)) yield env.timeout(5) child_process.interrupt('interrupt!') env.process(interruptor(env)) > env.run() tests/test_interrupts.py:25: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_interrupts.py::test_concurrent_interrupts
test_interrupts.py::test_concurrent_interrupts
env =, log = [] def test_concurrent_interrupts(env, log): """Concurrent interrupts are scheduled in the order in which they occurred. """ def fox(env, log): while True: try: yield env.timeout(10) except simpy.Interrupt as interrupt: log.append((env.now, interrupt.cause)) def farmer(env, name, fox): fox.interrupt(name) yield env.timeout(1) fantastic_mr_fox = env.process(fox(env, log)) for name in ('boggis', 'bunce', 'beans'): env.process(farmer(env, name, fantastic_mr_fox)) > env.run(20) tests/test_interrupts.py:49: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_interrupts.py::test_concurrent_interrupts_and_events
test_interrupts.py::test_concurrent_interrupts_and_events
env =, log = [] def test_concurrent_interrupts_and_events(env, log): """Interrupts interrupt a process while waiting for an event. Even if the event has happened concurrently with the interrupt.""" def fox(env, coup, log): while True: try: yield coup log.append(f'coup completed at {env.now}') except simpy.Interrupt: log.append(f'coup interrupted at {env.now}') else: return def master_plan(env, fox, coup): yield env.timeout(1) # Succeed and interrupt concurrently. coup.succeed() fox.interrupt() coup = env.event() fantastic_mr_fox = env.process(fox(env, coup, log)) env.process(master_plan(env, fantastic_mr_fox, coup)) > env.run(5) tests/test_interrupts.py:77: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_interrupts.py::test_init_interrupt
test_interrupts.py::test_init_interrupt
env =def test_init_interrupt(env): """An interrupt should always be executed after the Initialize event at the same time.""" def child(env): try: yield env.timeout(10) pytest.fail('Should have been interrupted.') except simpy.Interrupt: assert env.now == 0 def root(env): child_proc = env.process(child(env)) child_proc.interrupt() yield env.timeout(1) env.process(root(env)) > env.run() tests/test_interrupts.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_interrupts.py::test_interrupt_terminated_process
test_interrupts.py::test_interrupt_terminated_process
env =def test_interrupt_terminated_process(env): """Dead processes cannot be interrupted.""" def child(env): yield env.timeout(1) def parent(env): child_proc = env.process(child(env)) # Wait long enough so that child_proc terminates. yield env.timeout(2) ei = pytest.raises(RuntimeError, child_proc.interrupt) assert re.match( r' has terminated ' r'and cannot be interrupted.', ei.value.args[0], ) yield env.timeout(1) env.process(parent(env)) > env.run() tests/test_interrupts.py:123: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_interrupts.py::test_multiple_interrupts
test_interrupts.py::test_multiple_interrupts
env =def test_multiple_interrupts(env): """Interrupts on dead processes are discarded. If there are multiple concurrent interrupts on a process and the latter dies after handling the first interrupt, the remaining ones are silently ignored. """ def child(env): try: yield env.timeout(1) except simpy.Interrupt as i: return i.cause def parent(env): c = env.process(child(env)) yield env.timeout(0) c.interrupt(1) c.interrupt(2) result = yield c assert result == 1 env.process(parent(env)) > env.run() tests/test_interrupts.py:149: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_interrupts.py::test_interrupt_self
test_interrupts.py::test_interrupt_self
env =def test_interrupt_self(env): """A process should not be able to interrupt itself.""" def pem(env): pytest.raises(RuntimeError, env.active_process.interrupt) yield env.timeout(0) env.process(pem(env)) > env.run() tests/test_interrupts.py:160: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_interrupts.py::test_immediate_interrupt
test_interrupts.py::test_immediate_interrupt
env =, log = [] def test_immediate_interrupt(env, log): """Processes are immediately interruptable.""" def child(env, log): try: yield env.event() except simpy.Interrupt: log.append(env.now) def parent(env, log): child_proc = env.process(child(env, log)) child_proc.interrupt() return yield env.process(parent(env, log)) > env.run() tests/test_interrupts.py:179: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_interrupts.py::test_interrupt_event
test_interrupts.py::test_interrupt_event
env =def test_interrupt_event(env): """A process should be interruptable while waiting for an Event.""" def child(env): try: yield env.event() except simpy.Interrupt: assert env.now == 5 def parent(env): child_proc = env.process(child(env)) yield env.timeout(5) child_proc.interrupt() env.process(parent(env)) > env.run() tests/test_interrupts.py:200: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_interrupts.py::test_concurrent_behaviour
test_interrupts.py::test_concurrent_behaviour
env =def test_concurrent_behaviour(env): def proc_a(env): timeouts = [env.timeout(0) for i in range(2)] while timeouts: with pytest.raises(simpy.Interrupt): yield timeouts.pop(0) def proc_b(_, proc_a): for _ in range(2): proc_a.interrupt() return yield proc_a = env.process(proc_a(env)) env.process(proc_b(env, proc_a)) > env.run() tests/test_interrupts.py:219: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_process.py::test_get_state
test_process.py::test_get_state
env =def test_get_state(env): """A process is alive until it's generator has not terminated.""" def pem_a(env): yield env.timeout(3) def pem_b(env, pem_a): yield env.timeout(1) assert pem_a.is_alive yield env.timeout(3) assert not pem_a.is_alive proc_a = env.process(pem_a(env)) env.process(pem_b(env, proc_a)) > env.run() tests/test_process.py:36: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_process.py::test_target
test_process.py::test_target
env =def test_target(env): def pem(env, event): yield event event = env.timeout(5) proc = env.process(pem(env, event)) # Wait until "proc" is initialized and yielded the event while env.peek() < 5: > env.step() tests/test_process.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_process.py::test_wait_for_proc
test_process.py::test_wait_for_proc
env =def test_wait_for_proc(env): """A process can wait until another process finishes.""" def finisher(env): yield env.timeout(5) def waiter(env, finisher): proc = env.process(finisher(env)) yield proc # Waits until "proc" finishes assert env.now == 5 env.process(waiter(env, finisher)) > env.run() tests/test_process.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_process.py::test_return_value
test_process.py::test_return_value
env =def test_return_value(env): """Processes can set a return value.""" def child(env): yield env.timeout(1) return env.now def parent(env): result1 = yield env.process(child(env)) result2 = yield env.process(child(env)) assert [result1, result2] == [1, 2] env.process(parent(env)) > env.run() tests/test_process.py:83: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_process.py::test_child_exception
test_process.py::test_child_exception
env =def test_child_exception(env): """A child catches an exception and sends it to its parent.""" def child(env): yield env.timeout(1) return RuntimeError('Onoes!') def parent(env): result = yield env.process(child(env)) assert isinstance(result, Exception) env.process(parent(env)) > env.run() tests/test_process.py:98: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_process.py::test_interrupted_join
test_process.py::test_interrupted_join
env =def test_interrupted_join(env): """Interrupts remove a process from the callbacks of its target.""" def interruptor(env, process): yield env.timeout(1) process.interrupt() def child(env): yield env.timeout(2) def parent(env): child_proc = env.process(child(env)) try: yield child_proc pytest.fail('Did not receive an interrupt.') except Interrupt: assert env.now == 1 assert child_proc.is_alive # We should not get resumed when child terminates. yield env.timeout(5) assert env.now == 6 parent_proc = env.process(parent(env)) env.process(interruptor(env, parent_proc)) > env.run() tests/test_process.py:126: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_process.py::test_interrupted_join_and_rejoin
test_process.py::test_interrupted_join_and_rejoin
env =def test_interrupted_join_and_rejoin(env): """Tests that interrupts are raised while the victim is waiting for another process. The victim tries to join again. """ def interruptor(env, process): yield env.timeout(1) process.interrupt() def child(env): yield env.timeout(2) def parent(env): child_proc = env.process(child(env)) try: yield child_proc pytest.fail('Did not receive an interrupt.') except Interrupt: assert env.now == 1 assert child_proc.is_alive yield child_proc assert env.now == 2 parent_proc = env.process(parent(env)) env.process(interruptor(env, parent_proc)) > env.run() tests/test_process.py:156: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_resource
test_resources.py::test_resource
env =, log = [] def test_resource(env, log): """A *resource* is something with a limited numer of slots that need to be requested before and released after the usage (e.g., gas pumps at a gas station). """ def pem(env, name, resource, log): req = resource.request() yield req assert resource.count == 1 yield env.timeout(1) resource.release(req) log.append((name, env.now)) resource = simpy.Resource(env, capacity=1) assert resource.capacity == 1 assert resource.count == 0 env.process(pem(env, 'a', resource, log)) env.process(pem(env, 'b', resource, log)) > env.run() tests/test_resources.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_resource_context_manager
test_resources.py::test_resource_context_manager
env =, log = [] def test_resource_context_manager(env, log): """The event that ``Resource.request()`` returns can be used as Context Manager.""" def pem(env, name, resource, log): with resource.request() as request: yield request yield env.timeout(1) log.append((name, env.now)) resource = simpy.Resource(env, capacity=1) env.process(pem(env, 'a', resource, log)) env.process(pem(env, 'b', resource, log)) > env.run() tests/test_resources.py:62: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_resource_slots
test_resources.py::test_resource_slots
env =, log = [] def test_resource_slots(env, log): def pem(env, name, resource, log): with resource.request() as req: yield req log.append((name, env.now)) yield env.timeout(1) resource = simpy.Resource(env, capacity=3) for i in range(9): env.process(pem(env, str(i), resource, log)) > env.run() tests/test_resources.py:77: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_resource_continue_after_interrupt
test_resources.py::test_resource_continue_after_interrupt
env =def test_resource_continue_after_interrupt(env): """A process may be interrupted while waiting for a resource but should be able to continue waiting afterwards.""" def pem(env, res): with res.request() as req: yield req yield env.timeout(1) def victim(env, res): evt = res.request() try: yield evt pytest.fail('Should not have gotten the resource.') except simpy.Interrupt: yield evt res.release(evt) assert env.now == 1 def interruptor(proc): proc.interrupt() return 0 yield res = simpy.Resource(env, 1) env.process(pem(env, res)) proc = env.process(victim(env, res)) env.process(interruptor(proc)) > env.run() tests/test_resources.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_resource_release_after_interrupt
test_resources.py::test_resource_release_after_interrupt
env =def test_resource_release_after_interrupt(env): """A process needs to release a resource, even if it was interrupted and does not continue to wait for it.""" def blocker(env, res): with res.request() as req: yield req yield env.timeout(1) def victim(env, res): evt = res.request() try: yield evt pytest.fail('Should not have gotten the resource.') except simpy.Interrupt: # Don't wait for the resource res.release(evt) assert env.now == 0 def interruptor(proc): proc.interrupt() return 0 yield res = simpy.Resource(env, 1) env.process(blocker(env, res)) victim_proc = env.process(victim(env, res)) env.process(interruptor(victim_proc)) > env.run() tests/test_resources.py:151: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_resource_immediate_requests
test_resources.py::test_resource_immediate_requests
env =def test_resource_immediate_requests(env): """A process must not acquire a resource if it releases it and immediately requests it again while there are already other requesting processes.""" def child(env, res): result = [] for _ in range(3): with res.request() as req: yield req result.append(env.now) yield env.timeout(1) return result def parent(env): res = simpy.Resource(env, 1) child_a = env.process(child(env, res)) child_b = env.process(child(env, res)) a_acquire_times = yield child_a b_acquire_times = yield child_b assert a_acquire_times == [0, 2, 4] assert b_acquire_times == [1, 3, 5] env.process(parent(env)) > env.run() tests/test_resources.py:179: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_resource_cm_exception
test_resources.py::test_resource_cm_exception
env =, log = [] def test_resource_cm_exception(env, log): """Resource with context manager receives an exception.""" def process(env, resource, log, raise_): with resource.request() as req: yield req yield env.timeout(1) log.append(env.now) if raise_: with pytest.raises(ValueError, match='Foo'): raise ValueError('Foo') resource = simpy.Resource(env, 1) env.process(process(env, resource, log, True)) # The second process is used to check if it was able to access the # resource: env.process(process(env, resource, log, False)) > env.run() tests/test_resources.py:199: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_resource_with_condition
test_resources.py::test_resource_with_condition
env =def test_resource_with_condition(env): def process(env, resource): with resource.request() as res_event: result = yield res_event | env.timeout(1) assert res_event in result resource = simpy.Resource(env, 1) env.process(process(env, resource)) > env.run() tests/test_resources.py:212: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_resource_with_priority_queue
test_resources.py::test_resource_with_priority_queue
env =def test_resource_with_priority_queue(env): def process(env, delay, resource, priority, res_time): yield env.timeout(delay) req = resource.request(priority=priority) yield req assert env.now == res_time yield env.timeout(5) resource.release(req) resource = simpy.PriorityResource(env, capacity=1) env.process(process(env, 0, resource, 2, 0)) env.process(process(env, 2, resource, 3, 10)) env.process(process(env, 2, resource, 3, 15)) # Test equal priority env.process(process(env, 4, resource, 1, 5)) > env.run() tests/test_resources.py:229: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_sorted_queue_maxlen
test_resources.py::test_sorted_queue_maxlen
env =def test_sorted_queue_maxlen(env): """Requests must fail if more than *maxlen* requests happen concurrently.""" resource = simpy.PriorityResource(env, capacity=1) resource.put_queue.maxlen = 1 # pyright: ignore def process(env, resource): # The first request immediately triggered and does not enter the queue. resource.request(priority=1) # The second request is enqueued. resource.request(priority=1) with pytest.raises(RuntimeError, match='Cannot append event. Queue is full.'): # The third request will now fail. resource.request(priority=1) yield env.timeout(0) env.process(process(env, resource)) > env.run() tests/test_resources.py:249: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_get_users
test_resources.py::test_get_users
env =def test_get_users(env): def process(env, resource): with resource.request() as req: yield req yield env.timeout(1) resource = simpy.Resource(env, 1) procs = [env.process(process(env, resource)) for _ in range(3)] > env.run(until=1) tests/test_resources.py:260: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_preemptive_resource
test_resources.py::test_preemptive_resource
env =def test_preemptive_resource(env): """Processes with a higher priority may preempt requests of lower priority processes. Note that higher priorities are indicated by a lower number value.""" def proc_a(_, resource, prio): try: with resource.request(priority=prio) as req: yield req pytest.fail('Should have received an interrupt/preemption.') except simpy.Interrupt: pass def proc_b(_, resource, prio): with resource.request(priority=prio) as req: yield req resource = simpy.PreemptiveResource(env, 1) env.process(proc_a(env, resource, 1)) env.process(proc_b(env, resource, 0)) > env.run() tests/test_resources.py:293: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_preemptive_resource_timeout_0
test_resources.py::test_preemptive_resource_timeout_0
env =def test_preemptive_resource_timeout_0(env): def proc_a(env, resource, prio): with resource.request(priority=prio) as req: try: yield req yield env.timeout(1) pytest.fail('Should have received an interrupt/preemption.') except simpy.Interrupt: pass yield env.event() def proc_b(_, resource, prio): with resource.request(priority=prio) as req: yield req resource = simpy.PreemptiveResource(env, 1) env.process(proc_a(env, resource, 1)) env.process(proc_b(env, resource, 0)) > env.run() tests/test_resources.py:315: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_mixed_preemption
test_resources.py::test_mixed_preemption
env =, log = [] def test_mixed_preemption(env, log): def p(id, env, res, delay, prio, preempt, log): yield env.timeout(delay) with res.request(priority=prio, preempt=preempt) as req: try: yield req yield env.timeout(2) log.append((env.now, id)) except simpy.Interrupt as ir: assert ir is not None # noqa: PT017 assert isinstance(ir.cause, Preempted) # noqa: PT017 log.append((env.now, id, (ir.cause.by, ir.cause.usage_since))) res = simpy.PreemptiveResource(env, 1) # p0: First user: env.process(p(0, env, res, delay=0, prio=2, preempt=True, log=log)) # p1: Waits (cannot preempt): env.process(p(1, env, res, delay=0, prio=2, preempt=True, log=log)) # p2: Waits later, but has a higher prio: env.process(p(2, env, res, delay=1, prio=1, preempt=False, log=log)) # p3: Preempt the above proc: p3 = env.process(p(3, env, res, delay=3, prio=0, preempt=True, log=log)) # p4: Wait again: env.process(p(4, env, res, delay=4, prio=3, preempt=True, log=log)) > env.run() tests/test_resources.py:343: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_nested_preemption
test_resources.py::test_nested_preemption
env =, log = [] def test_nested_preemption(env, log): def process(id, env, res, delay, prio, preempt, log): yield env.timeout(delay) with res.request(priority=prio, preempt=preempt) as req: try: yield req yield env.timeout(5) log.append((env.now, id)) except simpy.Interrupt as ir: assert isinstance(ir.cause, Preempted) # noqa: PT017 log.append((env.now, id, (ir.cause.by, ir.cause.usage_since))) def process2(id, env, res0, res1, delay, prio, preempt, log): yield env.timeout(delay) with res0.request(priority=prio, preempt=preempt) as req0: try: yield req0 with res1.request(priority=prio, preempt=preempt) as req1: try: yield req1 yield env.timeout(5) log.append((env.now, id)) except simpy.Interrupt as ir: assert isinstance(ir.cause, Preempted) # noqa: PT017 log.append( ( env.now, id, (ir.cause.by, ir.cause.usage_since, ir.cause.resource), ) ) except simpy.Interrupt as ir: assert isinstance(ir.cause, Preempted) # noqa: PT017 log.append( ( env.now, id, (ir.cause.by, ir.cause.usage_since, ir.cause.resource), ) ) res0 = simpy.PreemptiveResource(env, 1) res1 = simpy.PreemptiveResource(env, 1) env.process(process2(0, env, res0, res1, 0, -1, True, log)) p1 = env.process(process(1, env, res1, 1, -2, True, log)) env.process(process2(2, env, res0, res1, 20, -1, True, log)) p3 = env.process(process(3, env, res0, 21, -2, True, log)) env.process(process2(4, env, res0, res1, 21, -1, True, log)) > env.run() tests/test_resources.py:406: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_container
test_resources.py::test_container
env =, log = [] def test_container(env, log): """A *container* is a resource (of optionally limited capacity) where you can put in our take-out a discrete or continuous amount of things (e.g., a box of lump sugar or a can of milk). The *put* and *get* operations block if the buffer is to full or to empty. If they return, the process knows that the *put* or *get* operation was successful. """ def putter(env, buf, log): yield env.timeout(1) while True: yield buf.put(2) log.append(('p', env.now)) yield env.timeout(1) def getter(env, buf, log): yield buf.get(1) log.append(('g', env.now)) yield env.timeout(1) yield buf.get(1) log.append(('g', env.now)) buf = simpy.Container(env, init=0, capacity=2) env.process(putter(env, buf, log)) env.process(getter(env, buf, log)) > env.run(until=5) tests/test_resources.py:450: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_container_get_queued
test_resources.py::test_container_get_queued
env =def test_container_get_queued(env): def proc(env, wait, container, what): yield env.timeout(wait) with getattr(container, what)(1) as req: yield req container = simpy.Container(env, 1) p0 = env.process(proc(env, 0, container, 'get')) env.process(proc(env, 1, container, 'put')) env.process(proc(env, 1, container, 'put')) p3 = env.process(proc(env, 1, container, 'put')) > env.run(until=1) tests/test_resources.py:467: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_store
test_resources.py::test_store
env =def test_store(env): """A store models the production and consumption of concrete python objects (in contrast to containers, where you only now if the *put* or *get* operations were successful but don't get concrete objects). """ def putter(_, store, item): yield store.put(item) def getter(_, store, orig_item): item = yield store.get() assert item is orig_item store = simpy.Store(env, capacity=2) item = object() # NOTE: Does the start order matter? Need to test this. env.process(putter(env, store, item)) env.process(getter(env, store, item)) > env.run() tests/test_resources.py:535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_store_capacity
test_resources.py::test_store_capacity
env =def test_store_capacity(env): with pytest.raises(ValueError, match='"capacity" must be > 0'): simpy.Store(env, 0) with pytest.raises(ValueError, match='"capacity" must be > 0'): simpy.Store(env, -1) capacity = 2 store = simpy.Store(env, capacity) env.process(store.put(i) for i in range(capacity + 1)) > env.run() tests/test_resources.py:559: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_store_cancel
test_resources.py::test_store_cancel
env =def test_store_cancel(env): store = simpy.Store(env, capacity=1) def acquire_implicit_cancel(): with store.get(): yield env.timeout(1) # implicit cancel() when exiting with-block env.process(acquire_implicit_cancel()) > env.run() tests/test_resources.py:574: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_priority_store_item_priority
test_resources.py::test_priority_store_item_priority
env =def test_priority_store_item_priority(env): pstore = simpy.PriorityStore(env, 3) log = [] def getter(wait): yield env.timeout(wait) item = yield pstore.get() log.append(item) # Do not specify priority; the items themselves will be compared to # determine priority. env.process(pstore.put(s) for s in 'bcadefg') env.process(getter(1)) env.process(getter(2)) env.process(getter(3)) > env.run() tests/test_resources.py:592: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_priority_store_stable_order
test_resources.py::test_priority_store_stable_order
env =def test_priority_store_stable_order(env): pstore = simpy.PriorityStore(env, 3) log = [] def getter(wait): yield env.timeout(wait) _, item = yield pstore.get() log.append(item) items = [object() for _ in range(3)] # Unorderable items are inserted with same priority. env.process(pstore.put(simpy.PriorityItem(0, item)) for item in items) env.process(getter(1)) env.process(getter(2)) env.process(getter(3)) > env.run() tests/test_resources.py:612: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_filter_store
test_resources.py::test_filter_store
env =def test_filter_store(env): def pem(env): store = simpy.FilterStore(env, capacity=2) get_event = store.get(lambda item: item == 'b') yield store.put('a') assert not get_event.triggered yield store.put('b') assert get_event.triggered env.process(pem(env)) > env.run() tests/test_resources.py:630: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_filter_store_get_after_mismatch
test_resources.py::test_filter_store_get_after_mismatch
env =def test_filter_store_get_after_mismatch(env): """Regression test for issue #49. Triggering get-events after a put in FilterStore wrongly breaks after the first mismatch. """ def putter(env, store): # The order of putting 'spam' before 'eggs' is important here. yield store.put('spam') yield env.timeout(1) yield store.put('eggs') def getter(store): # The order of requesting 'eggs' before 'spam' is important here. eggs = store.get(lambda i: i == 'eggs') spam = store.get(lambda i: i == 'spam') ret = yield spam | eggs assert spam in ret assert eggs not in ret assert env.now == 0 yield eggs assert env.now == 1 store = simpy.FilterStore(env, capacity=2) env.process(getter(store)) env.process(putter(env, store)) > env.run() tests/test_resources.py:663: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_filter_calls_best_case
test_resources.py::test_filter_calls_best_case
env =def test_filter_calls_best_case(env): """The filter function is called every item in the store until a match is found. In the best case the first item already matches.""" log = [] def log_filter(item): log.append(f'check {item}') return True store = simpy.FilterStore(env) store.items = [1, 2, 3] def getter(store): log.append(f'get {yield store.get(log_filter)}') log.append(f'get {yield store.get(log_filter)}') log.append(f'get {yield store.get(log_filter)}') env.process(getter(store)) > env.run() tests/test_resources.py:684: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_filter_calls_worst_case
test_resources.py::test_filter_calls_worst_case
env =def test_filter_calls_worst_case(env): """In the worst case the filter function is being called for items multiple times.""" log = [] store = simpy.FilterStore(env) def putter(store): for i in range(4): log.append(f'put {i}') yield store.put(i) def log_filter(item): log.append(f'check {item}') return item >= 3 def getter(store): log.append(f'get {yield store.get(log_filter)}') env.process(getter(store)) env.process(putter(store)) > env.run() tests/test_resources.py:710: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_resources.py::test_immediate_put_request
test_resources.py::test_immediate_put_request
env =def test_immediate_put_request(env): """Put requests that can be fulfilled immediately do not enter the put queue.""" resource = simpy.Resource(env, capacity=1) assert len(resource.users) == 0 assert len(resource.queue) == 0 # The resource is empty, the first request will succeed immediately without # entering the queue. > request = resource.request() tests/test_resources.py:733: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/resources/resource.py:74: in __init__ super().__init__(resource) src/simpy/resources/base.py:39: in __init__ resource._trigger_put(None) src/simpy/resources/base.py:199: in _trigger_put if not self._do_put(put_event): _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = event = def _do_put(self, event: PutType) ->Optional[bool]: """Perform the *put* operation. This method needs to be implemented by subclasses. If the conditions for the put *event* are met, the method must trigger the event (e.g. call :meth:`Event.succeed()` with an appropriate value). This method is called by :meth:`_trigger_put` for every event in the :attr:`put_queue`, as long as the return value does not evaluate ``False``. """ > raise NotImplementedError("The _do_put() method has to be implemented by subclasses.") E NotImplementedError: The _do_put() method has to be implemented by subclasses. src/simpy/resources/base.py:186: NotImplementedError
test_resources.py::test_immediate_get_request
test_resources.py::test_immediate_get_request
env =def test_immediate_get_request(env): """Get requests that can be fulfilled immediately do not enter the get queue.""" container = simpy.Container(env) # Put something in the container, this request is triggered immediately # without entering the queue. > request = container.put(1) tests/test_resources.py:751: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/resources/container.py:30: in __init__ super().__init__(container) src/simpy/resources/base.py:39: in __init__ resource._trigger_put(None) src/simpy/resources/base.py:199: in _trigger_put if not self._do_put(put_event): _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = event = def _do_put(self, event: PutType) ->Optional[bool]: """Perform the *put* operation. This method needs to be implemented by subclasses. If the conditions for the put *event* are met, the method must trigger the event (e.g. call :meth:`Event.succeed()` with an appropriate value). This method is called by :meth:`_trigger_put` for every event in the :attr:`put_queue`, as long as the return value does not evaluate ``False``. """ > raise NotImplementedError("The _do_put() method has to be implemented by subclasses.") E NotImplementedError: The _do_put() method has to be implemented by subclasses. src/simpy/resources/base.py:186: NotImplementedError
test_rt.py::test_rt[0.1]
test_rt.py::test_rt[0.1]
log = [], factor = 0.1 @pytest.mark.parametrize('factor', [0.1, 0.05, 0.15]) def test_rt(log, factor): """Basic tests for run().""" start = monotonic() env = RealtimeEnvironment(factor=factor) env.process(process(env, log, 0.01, 1)) env.process(process(env, log, 0.02, 1)) > env.run(2) tests/test_rt.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self =def step(self) ->None: """Process the next event after enough real-time has passed for the event to happen. The delay is scaled according to the real-time :attr:`factor`. With :attr:`strict` mode enabled, a :exc:`RuntimeError` will be raised, if the event is processed too slowly. """ try: evt_time = self.peek() except EmptySchedule: return real_time = monotonic() expected_real_time = self.real_start + (evt_time - self.env_start) / self._factor if real_time < expected_real_time: sleep(expected_real_time - real_time) elif self._strict and real_time > expected_real_time: > raise RuntimeError(f'Simulation too slow: {real_time - expected_real_time:.3f} seconds late') E RuntimeError: Simulation too slow: 0.000 seconds late src/simpy/rt.py:74: RuntimeError
test_rt.py::test_rt[0.05]
test_rt.py::test_rt[0.05]
log = [], factor = 0.05 @pytest.mark.parametrize('factor', [0.1, 0.05, 0.15]) def test_rt(log, factor): """Basic tests for run().""" start = monotonic() env = RealtimeEnvironment(factor=factor) env.process(process(env, log, 0.01, 1)) env.process(process(env, log, 0.02, 1)) > env.run(2) tests/test_rt.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self =def step(self) ->None: """Process the next event after enough real-time has passed for the event to happen. The delay is scaled according to the real-time :attr:`factor`. With :attr:`strict` mode enabled, a :exc:`RuntimeError` will be raised, if the event is processed too slowly. """ try: evt_time = self.peek() except EmptySchedule: return real_time = monotonic() expected_real_time = self.real_start + (evt_time - self.env_start) / self._factor if real_time < expected_real_time: sleep(expected_real_time - real_time) elif self._strict and real_time > expected_real_time: > raise RuntimeError(f'Simulation too slow: {real_time - expected_real_time:.3f} seconds late') E RuntimeError: Simulation too slow: 0.000 seconds late src/simpy/rt.py:74: RuntimeError
test_rt.py::test_rt[0.15]
test_rt.py::test_rt[0.15]
log = [], factor = 0.15 @pytest.mark.parametrize('factor', [0.1, 0.05, 0.15]) def test_rt(log, factor): """Basic tests for run().""" start = monotonic() env = RealtimeEnvironment(factor=factor) env.process(process(env, log, 0.01, 1)) env.process(process(env, log, 0.02, 1)) > env.run(2) tests/test_rt.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self =def step(self) ->None: """Process the next event after enough real-time has passed for the event to happen. The delay is scaled according to the real-time :attr:`factor`. With :attr:`strict` mode enabled, a :exc:`RuntimeError` will be raised, if the event is processed too slowly. """ try: evt_time = self.peek() except EmptySchedule: return real_time = monotonic() expected_real_time = self.real_start + (evt_time - self.env_start) / self._factor if real_time < expected_real_time: sleep(expected_real_time - real_time) elif self._strict and real_time > expected_real_time: > raise RuntimeError(f'Simulation too slow: {real_time - expected_real_time:.3f} seconds late') E RuntimeError: Simulation too slow: 0.000 seconds late src/simpy/rt.py:74: RuntimeError
test_rt.py::test_rt_multiple_call
test_rt.py::test_rt_multiple_call
log = [] def test_rt_multiple_call(log): """Test multiple calls to run().""" start = monotonic() env = RealtimeEnvironment(factor=0.05) env.process(process(env, log, 0.01, 2)) env.process(process(env, log, 0.01, 3)) > env.run(5) tests/test_rt.py:47: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self =def step(self) ->None: """Process the next event after enough real-time has passed for the event to happen. The delay is scaled according to the real-time :attr:`factor`. With :attr:`strict` mode enabled, a :exc:`RuntimeError` will be raised, if the event is processed too slowly. """ try: evt_time = self.peek() except EmptySchedule: return real_time = monotonic() expected_real_time = self.real_start + (evt_time - self.env_start) / self._factor if real_time < expected_real_time: sleep(expected_real_time - real_time) elif self._strict and real_time > expected_real_time: > raise RuntimeError(f'Simulation too slow: {real_time - expected_real_time:.3f} seconds late') E RuntimeError: Simulation too slow: 0.000 seconds late src/simpy/rt.py:74: RuntimeError
test_rt.py::test_rt_slow_sim_default_behavior
test_rt.py::test_rt_slow_sim_default_behavior
log = [] def test_rt_slow_sim_default_behavior(log): """By default, SimPy should raise an error if a simulation is too slow for the selected real-time factor.""" env = RealtimeEnvironment(factor=0.05) env.process(process(env, log, 0.1, 1)) err = pytest.raises(RuntimeError, env.run, 3) > assert 'Simulation too slow for real time' in str(err.value) E AssertionError: assert 'Simulation too slow for real time' in 'Simulation too slow: 0.000 seconds late' E + where 'Simulation too slow: 0.000 seconds late' = str(RuntimeError('Simulation too slow: 0.000 seconds late')) E + where RuntimeError('Simulation too slow: 0.000 seconds late') =.value tests/test_rt.py:68: AssertionError
test_rt.py::test_rt_slow_sim_no_error
test_rt.py::test_rt_slow_sim_no_error
log = [] def test_rt_slow_sim_no_error(log): """Test ignoring slow simulations.""" start = monotonic() env = RealtimeEnvironment(factor=0.05, strict=False) env.process(process(env, log, 0.1, 1)) > env.run(2) tests/test_rt.py:78: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() src/simpy/rt.py:76: in step super().step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self =def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_rt.py::test_rt_illegal_until
test_rt.py::test_rt_illegal_until
def test_rt_illegal_until(): """Test illegal value for *until*.""" env = RealtimeEnvironment() > with pytest.raises( ValueError, match=r'until \(-1\) must be greater than the current simulation time', ): E Failed: DID NOT RAISEtests/test_rt.py:88: Failed
test_rt.py::test_rt_sync
test_rt.py::test_rt_sync
log = [] def test_rt_sync(log): """Test resetting the internal wall-clock reference time.""" env = RealtimeEnvironment(factor=0.05) env.process(process(env, log, 0.01)) sleep(0.06) # Simulate massive workload :-) env.sync() > env.run(3) tests/test_rt.py:101: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self =def step(self) ->None: """Process the next event after enough real-time has passed for the event to happen. The delay is scaled according to the real-time :attr:`factor`. With :attr:`strict` mode enabled, a :exc:`RuntimeError` will be raised, if the event is processed too slowly. """ try: evt_time = self.peek() except EmptySchedule: return real_time = monotonic() expected_real_time = self.real_start + (evt_time - self.env_start) / self._factor if real_time < expected_real_time: sleep(expected_real_time - real_time) elif self._strict and real_time > expected_real_time: > raise RuntimeError(f'Simulation too slow: {real_time - expected_real_time:.3f} seconds late') E RuntimeError: Simulation too slow: 0.000 seconds late src/simpy/rt.py:74: RuntimeError
test_rt.py::test_run_with_untriggered_event
test_rt.py::test_run_with_untriggered_event
env =def test_run_with_untriggered_event(env): env = RealtimeEnvironment(factor=0.05) > excinfo = pytest.raises(RuntimeError, env.run, until=env.event()) tests/test_rt.py:106: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:183: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event after enough real-time has passed for the event to happen. The delay is scaled according to the real-time :attr:`factor`. With :attr:`strict` mode enabled, a :exc:`RuntimeError` will be raised, if the event is processed too slowly. """ try: evt_time = self.peek() except EmptySchedule: return real_time = monotonic() expected_real_time = self.real_start + (evt_time - self.env_start) / self._factor if real_time < expected_real_time: > sleep(expected_real_time - real_time) E OverflowError: timestamp too large to convert to C _PyTime_t src/simpy/rt.py:72: OverflowError
test_timeout.py::test_discrete_time_steps
test_timeout.py::test_discrete_time_steps
env =, log = [] def test_discrete_time_steps(env, log): """envple envulation with discrete time steps.""" def pem(env, log): while True: log.append(env.now) yield env.timeout(delay=1) env.process(pem(env, log)) > env.run(until=3) tests/test_timeout.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:192: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_timeout.py::test_negative_timeout
test_timeout.py::test_negative_timeout
env =def test_negative_timeout(env): """Don't allow negative timeout times.""" def pem(env): yield env.timeout(-1) env.process(pem(env)) with pytest.raises(ValueError, match='Negative delay'): > env.run() tests/test_timeout.py:31: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_timeout.py::test_timeout_value
test_timeout.py::test_timeout_value
env =def test_timeout_value(env): """You can pass an additional *value* to *timeout* which will be directly yielded back into the PEM. This is useful to implement some kinds of resources or other additions. See :class:`envpy.resources.Store` for an example. """ def pem(env): val = yield env.timeout(1, 'ohai') assert val == 'ohai' env.process(pem(env)) > env.run() tests/test_timeout.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_timeout.py::test_shared_timeout
test_timeout.py::test_shared_timeout
env =, log = [] def test_shared_timeout(env, log): def child(env, timeout, id, log): yield timeout log.append((id, env.now)) timeout = env.timeout(1) for i in range(3): env.process(child(env, timeout, i, log)) > env.run() tests/test_timeout.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_timeout.py::test_triggered_timeout
test_timeout.py::test_triggered_timeout
env =def test_triggered_timeout(env): def process(env): def child(env, event): value = yield event return value event = env.timeout(1, 'i was already done') # Start the child after the timeout has already happened. yield env.timeout(2) value = yield env.process(child(env, event)) assert value == 'i was already done' > env.run(env.process(process(env))) tests/test_timeout.py:76: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:183: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_start_delayed
test_util.py::test_start_delayed
env =def test_start_delayed(env): def pem(env): assert env.now == 5 yield env.timeout(1) start_delayed(env, pem(env), delay=5) > env.run() tests/test_util.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_subscribe
test_util.py::test_subscribe
env =def test_subscribe(env): """Check async. interrupt if a process terminates.""" def child(env): yield env.timeout(3) return 'ohai' def parent(env): child_proc = env.process(child(env)) subscribe_at(child_proc) try: yield env.event() except Interrupt as interrupt: assert interrupt.cause is not None # noqa: PT017 assert interrupt.cause[0] is child_proc # noqa: PT017 assert interrupt.cause[1] == 'ohai' # noqa: PT017 assert env.now == 3 env.process(parent(env)) > env.run() tests/test_util.py:51: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_subscribe_terminated_proc
test_util.py::test_subscribe_terminated_proc
env =def test_subscribe_terminated_proc(env): """subscribe() proc should send a signal immediately if "other" has already terminated. """ def child(env): yield env.timeout(1) def parent(env): child_proc = env.process(child(env)) yield env.timeout(2) pytest.raises(RuntimeError, subscribe_at, child_proc) env.process(parent(env)) > env.run() tests/test_util.py:69: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_subscribe_with_join
test_util.py::test_subscribe_with_join
env =def test_subscribe_with_join(env): """Test that subscribe() works if a process waits for another one.""" def child(env, i): yield env.timeout(i) def parent(env): child_proc1 = env.process(child(env, 1)) child_proc2 = env.process(child(env, 2)) try: subscribe_at(child_proc1) yield child_proc2 except Interrupt as interrupt: assert env.now == 1 assert interrupt.cause is not None # noqa: PT017 assert interrupt.cause[0] is child_proc1 # noqa: PT017 assert child_proc2.is_alive env.process(parent(env)) > env.run() tests/test_util.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_subscribe_at_timeout
test_util.py::test_subscribe_at_timeout
env =def test_subscribe_at_timeout(env): """You should be able to subscribe at arbitrary events.""" def pem(env): to = env.timeout(2) subscribe_at(to) try: yield env.timeout(10) except Interrupt as interrupt: assert interrupt.cause == (to, None) # noqa: PT017 assert env.now == 2 env.process(pem(env)) > env.run() tests/test_util.py:107: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_subscribe_at_timeout_with_value
test_util.py::test_subscribe_at_timeout_with_value
env =def test_subscribe_at_timeout_with_value(env): """An event's value should be accessible via the interrupt cause.""" def pem(env): val = 'ohai' to = env.timeout(2, value=val) subscribe_at(to) try: yield env.timeout(10) except Interrupt as interrupt: assert interrupt.cause == (to, val) # noqa: PT017 assert env.now == 2 env.process(pem(env)) > env.run() tests/test_util.py:124: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_all_of
test_util.py::test_all_of
env =def test_all_of(env): """Wait for all events to be triggered.""" def parent(env): # Start 10 events. events = [env.timeout(i, value=i) for i in range(10)] results = yield env.all_of(events) assert results == {events[i]: i for i in range(10)} assert env.now == 9 env.process(parent(env)) > env.run() tests/test_util.py:139: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_all_of_generator
test_util.py::test_all_of_generator
env =def test_all_of_generator(env): """Conditions also work with generators.""" def parent(env): # Start 10 events. events = (env.timeout(i, value=i) for i in range(10)) results = yield env.all_of(events) assert list(results.values()) == list(range(10)) assert env.now == 9 env.process(parent(env)) > env.run() tests/test_util.py:154: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_wait_for_all_with_errors
test_util.py::test_wait_for_all_with_errors
env =def test_wait_for_all_with_errors(env): """On default AllOf should fail immediately if one of its events fails.""" def child_with_error(env, value): yield env.timeout(value) raise RuntimeError('crashing') def parent(env): events = [ env.timeout(1, value=1), env.process(child_with_error(env, 2)), env.timeout(3, value=3), ] condition = env.all_of(events) with pytest.raises(RuntimeError, match='crashing'): yield condition # Although the condition has failed, interim values are available. assert condition._events[0].value == 1 assert condition._events[1].value.args[0] == 'crashing' # The last child has not terminated yet. assert not events[2].processed env.process(parent(env)) > env.run() tests/test_util.py:183: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_all_of_chaining
test_util.py::test_all_of_chaining
env =def test_all_of_chaining(env): """If a wait_for_all condition A is chained to a wait_for_all condition B, B will be merged into A.""" def parent(env): condition_a = env.all_of([env.timeout(i, value=i) for i in range(2)]) condition_b = env.all_of([env.timeout(i, value=i) for i in range(2)]) condition_a &= condition_b results = yield condition_a assert list(results.values()) == [0, 1, 0, 1] env.process(parent(env)) > env.run() tests/test_util.py:200: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_all_of_chaining_intermediate_results
test_util.py::test_all_of_chaining_intermediate_results
env =def test_all_of_chaining_intermediate_results(env): """If a wait_for_all condition A with intermediate results is merged into another wait_for_all condition B, the results are copied into condition A.""" def parent(env): condition_a = env.all_of([env.timeout(i, value=i) for i in range(2)]) condition_b = env.all_of([env.timeout(i, value=i) for i in range(2)]) yield env.timeout(0) condition = condition_a & condition_b result = ConditionValue() condition._populate_value(result) assert list(result.values()) == [0, 0] results = yield condition assert list(results.values()) == [0, 1, 0, 1] env.process(parent(env)) > env.run() tests/test_util.py:223: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_all_of_with_triggered_events
test_util.py::test_all_of_with_triggered_events
env =def test_all_of_with_triggered_events(env): """Processed events can be added to a condition. Confirm this with all_of.""" def parent(env): events = [env.timeout(0, value='spam'), env.timeout(1, value='eggs')] yield env.timeout(2) values = list((yield env.all_of(events)).values()) assert values == ['spam', 'eggs'] env.process(parent(env)) > env.run() tests/test_util.py:238: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_any_of
test_util.py::test_any_of
env =def test_any_of(env): """Wait for any event to be triggered.""" def parent(env): # Start 10 events. events = [env.timeout(i, value=i) for i in range(10)] results = yield env.any_of(events) assert results == {events[0]: 0} assert env.now == 0 env.process(parent(env)) > env.run() tests/test_util.py:253: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_any_of_with_errors
test_util.py::test_any_of_with_errors
env =def test_any_of_with_errors(env): """On default any_of should fail if the event has failed too.""" def child_with_error(env, value): yield env.timeout(value) raise RuntimeError('crashing') def parent(env): events = [env.process(child_with_error(env, 1)), env.timeout(2, value=2)] condition = env.any_of(events) with pytest.raises(RuntimeError, match='crashing'): yield condition assert condition._events[0].value.args[0] == 'crashing' # The last event has not terminated yet. assert not events[1].processed env.process(parent(env)) > env.run() tests/test_util.py:274: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_any_of_chaining
test_util.py::test_any_of_chaining
env =def test_any_of_chaining(env): """If a any_of condition A is chained to a any_of condition B, B will be merged into A.""" def parent(env): condition_a = env.any_of([env.timeout(2, value='a')]) condition_b = env.any_of([env.timeout(1, value='b')]) condition_a |= condition_b results = yield condition_a assert list(results.values()) == ['b'] env.process(parent(env)) > env.run() tests/test_util.py:291: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_any_of_with_triggered_events
test_util.py::test_any_of_with_triggered_events
env =def test_any_of_with_triggered_events(env): """Processed events can be added to a condition. Confirm this with all_of.""" def parent(env): events = [env.timeout(0, value='spam'), env.timeout(1, value='eggs')] yield env.timeout(2) values = list((yield env.any_of(events)).values()) assert values == ['spam', 'eggs'] env.process(parent(env)) > env.run() tests/test_util.py:306: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_empty_any_of
test_util.py::test_empty_any_of
env =def test_empty_any_of(env): """AnyOf will trigger immediately if there are no events.""" def parent(env): results = yield env.any_of([]) assert results == {} env.process(parent(env)) > env.run() tests/test_util.py:317: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_empty_all_of
test_util.py::test_empty_all_of
env =def test_empty_all_of(env): """AllOf will trigger immediately if there are no events.""" def parent(env): results = yield env.all_of([]) assert results == {} env.process(parent(env)) > env.run() tests/test_util.py:328: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
test_util.py::test_all_of_expansion
test_util.py::test_all_of_expansion
env =def test_all_of_expansion(env): """The result of AllOf is an OrderedDict, which allows to expand its values directly into variables.""" def p(env): timeouts = [env.timeout(d, d) for d in [3, 2, 1]] a, b, c = (yield env.all_of(timeouts)).values() assert a == 3 assert b == 2 assert c == 1 env.process(p(env)) > env.run() tests/test_util.py:343: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/simpy/core.py:176: in run self.step() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def step(self) ->None: """Process the next event. Raise an :exc:`EmptySchedule` if no further events are available. """ try: self._now, _, _, event = heappop(self._queue) except IndexError: raise EmptySchedule() # Process the event event._ok = True > event._value = event._callback(event) E AttributeError: 'Initialize' object has no attribute '_callback'. Did you mean: 'callbacks'? src/simpy/core.py:150: AttributeError
Patch diff
diff --git a/src/simpy/core.py b/src/simpy/core.py
index 10c88fb..b39ddef 100644
--- a/src/simpy/core.py
+++ b/src/simpy/core.py
@@ -34,7 +34,10 @@ class BoundClass(Generic[T]):
def bind_early(instance: object) ->None:
"""Bind all :class:`BoundClass` attributes of the *instance's* class
to the instance itself to increase performance."""
- pass
+ cls = type(instance)
+ for name, obj in cls.__dict__.items():
+ if isinstance(obj, BoundClass):
+ setattr(instance, name, obj.__get__(instance, cls))
class EmptySchedule(Exception):
@@ -49,7 +52,7 @@ class StopSimulation(Exception):
def callback(cls, event: Event) ->None:
"""Used as callback in :meth:`Environment.run()` to stop the simulation
when the *until* event occurred."""
- pass
+ raise cls()
SimTime = Union[int, float]
@@ -77,12 +80,12 @@ class Environment:
@property
def now(self) ->SimTime:
"""The current simulation time."""
- pass
+ return self._now
@property
def active_process(self) ->Optional[Process]:
"""The currently active process of the environment."""
- pass
+ return self._active_proc
if TYPE_CHECKING:
def process(self, generator: ProcessGenerator) ->Process:
@@ -121,12 +124,15 @@ class Environment:
def schedule(self, event: Event, priority: EventPriority=NORMAL, delay:
SimTime=0) ->None:
"""Schedule an *event* with a given *priority* and a *delay*."""
- pass
+ heappush(self._queue, (self._now + delay, priority, next(self._eid), event))
def peek(self) ->SimTime:
"""Get the time of the next scheduled event. Return
:data:`~simpy.core.Infinity` if there is no further event."""
- pass
+ try:
+ return self._queue[0][0]
+ except IndexError:
+ return Infinity
def step(self) ->None:
"""Process the next event.
@@ -134,7 +140,20 @@ class Environment:
Raise an :exc:`EmptySchedule` if no further events are available.
"""
- pass
+ try:
+ self._now, _, _, event = heappop(self._queue)
+ except IndexError:
+ raise EmptySchedule()
+
+ # Process the event
+ event._ok = True
+ event._value = event._callback(event)
+ event._processed = True
+
+ if isinstance(event, Process):
+ self._active_proc = event
+ else:
+ self._active_proc = None
def run(self, until: Optional[Union[SimTime, Event]]=None) ->Optional[Any]:
"""Executes :meth:`step()` until the given criterion *until* is met.
@@ -151,4 +170,27 @@ class Environment:
until the environment's time reaches *until*.
"""
- pass
+ if until is None:
+ while True:
+ try:
+ self.step()
+ except EmptySchedule:
+ return None
+ elif isinstance(until, Event):
+ until.callbacks.append(StopSimulation.callback)
+ try:
+ while not until.triggered:
+ self.step()
+ except StopSimulation:
+ return until.value
+ except EmptySchedule:
+ if not until.triggered:
+ raise RuntimeError('No scheduled events left but "until" event was not triggered')
+ elif isinstance(until, (int, float)):
+ try:
+ while self._now < until:
+ self.step()
+ except EmptySchedule:
+ return None
+ else:
+ raise ValueError('Invalid until parameter type')
diff --git a/src/simpy/events.py b/src/simpy/events.py
index 128ed75..2781b3f 100644
--- a/src/simpy/events.py
+++ b/src/simpy/events.py
@@ -75,19 +75,19 @@ class Event:
def _desc(self) ->str:
"""Return a string *Event()*."""
- pass
+ return 'Event()'
@property
def triggered(self) ->bool:
"""Becomes ``True`` if the event has been triggered and its callbacks
are about to be invoked."""
- pass
+ return self._value is not PENDING
@property
def processed(self) ->bool:
"""Becomes ``True`` if the event has been processed (e.g., its
callbacks have been invoked)."""
- pass
+ return self.callbacks is None
@property
def ok(self) ->bool:
@@ -98,7 +98,9 @@ class Event:
:raises AttributeError: if accessed before the event is triggered.
"""
- pass
+ if self._value is PENDING:
+ raise AttributeError('Event has not yet been triggered')
+ return self._ok
@property
def defused(self) ->bool:
@@ -115,7 +117,7 @@ class Event:
processed by the :class:`~simpy.core.Environment`.
"""
- pass
+ return self._defused
@property
def value(self) ->Optional[Any]:
@@ -126,7 +128,9 @@ class Event:
Raises :exc:`AttributeError` if the value is not yet available.
"""
- pass
+ if self._value is PENDING:
+ raise AttributeError('Value not yet available')
+ return self._value
def trigger(self, event: Event) ->None:
"""Trigger the event with the state and value of the provided *event*.
@@ -136,7 +140,10 @@ class Event:
chain reactions.
"""
- pass
+ self._ok = event._ok
+ self._value = event._value
+ self._defused = event._defused
+ self.env.schedule(self)
def succeed(self, value: Optional[Any]=None) ->Event:
"""Set the event's value, mark it as successful and schedule it for
@@ -145,7 +152,12 @@ class Event:
Raises :exc:`RuntimeError` if this event has already been triggerd.
"""
- pass
+ if self._value is not PENDING:
+ raise RuntimeError('Event has already been triggered')
+ self._ok = True
+ self._value = value
+ self.env.schedule(self)
+ return self
def fail(self, exception: Exception) ->Event:
"""Set *exception* as the events value, mark it as failed and schedule
@@ -156,7 +168,15 @@ class Event:
Raises :exc:`RuntimeError` if this event has already been triggered.
"""
- pass
+ if not isinstance(exception, Exception):
+ raise TypeError('exception must be an Exception instance')
+ if self._value is not PENDING:
+ raise RuntimeError('Event has already been triggered')
+ self._ok = False
+ self._value = exception
+ self._defused = False
+ self.env.schedule(self)
+ return self
def __and__(self, other: Event) ->Condition:
"""Return a :class:`~simpy.events.Condition` that will be triggered if
@@ -197,7 +217,8 @@ class Timeout(Event):
def _desc(self) ->str:
"""Return a string *Timeout(delay[, value=value])*."""
- pass
+ value_str = f', value={self._value!r}' if self._value is not None else ''
+ return f'Timeout({self._delay}{value_str})'
class Initialize(Event):
@@ -267,7 +288,7 @@ class Process(Event):
def _desc(self) ->str:
"""Return a string *Process(process_func_name)*."""
- pass
+ return f'Process({self._generator.__name__})'
@property
def target(self) ->Event:
@@ -277,17 +298,17 @@ class Process(Event):
interrupted.
"""
- pass
+ return self._target
@property
def name(self) ->str:
"""Name of the function used to start the process."""
- pass
+ return self._generator.__name__
@property
def is_alive(self) ->bool:
"""``True`` until the process generator exits."""
- pass
+ return self._value is PENDING
def interrupt(self, cause: Optional[Any]=None) ->None:
"""Interrupt this process optionally providing a *cause*.
@@ -297,7 +318,12 @@ class Process(Event):
cases.
"""
- pass
+ if not self.is_alive:
+ raise RuntimeError(f'{self} has terminated and cannot be interrupted.')
+ if self is self.env.active_process:
+ raise RuntimeError('A process is not allowed to interrupt itself.')
+
+ Interruption(self, cause)
def _resume(self, event: Event) ->None:
"""Resumes the execution of the process with the value of *event*. If
@@ -383,16 +409,24 @@ class Condition(Event):
def _desc(self) ->str:
"""Return a string *Condition(evaluate, [events])*."""
- pass
+ return f'Condition({self._evaluate.__name__}, {self._events})'
def _populate_value(self, value: ConditionValue) ->None:
"""Populate the *value* by recursively visiting all nested
conditions."""
- pass
+ for event in self._events:
+ if isinstance(event, Condition):
+ event._populate_value(value)
+ elif event.callbacks is None:
+ value.events.append(event)
def _build_value(self, event: Event) ->None:
"""Build the value of this condition."""
- pass
+ if not self._ok:
+ return
+ value = ConditionValue()
+ self._populate_value(value)
+ self._value = value
def _remove_check_callbacks(self) ->None:
"""Remove _check() callbacks from events recursively.
@@ -403,24 +437,36 @@ class Condition(Event):
untriggered events.
"""
- pass
+ for event in self._events:
+ if event.callbacks and self._check in event.callbacks:
+ event.callbacks.remove(self._check)
+ if isinstance(event, Condition):
+ event._remove_check_callbacks()
def _check(self, event: Event) ->None:
"""Check if the condition was already met and schedule the *event* if
so."""
- pass
+ if self._value is not PENDING:
+ return
+
+ self._count += 1
+
+ if self._evaluate(self._events, self._count):
+ self._ok = True
+ self.env.schedule(self)
+ self._remove_check_callbacks()
@staticmethod
def all_events(events: Tuple[Event, ...], count: int) ->bool:
"""An evaluation function that returns ``True`` if all *events* have
been triggered."""
- pass
+ return len(events) == count
@staticmethod
def any_events(events: Tuple[Event, ...], count: int) ->bool:
"""An evaluation function that returns ``True`` if at least one of
*events* has been triggered."""
- pass
+ return count > 0
class AllOf(Condition):
@@ -447,4 +493,7 @@ class AnyOf(Condition):
def _describe_frame(frame: FrameType) ->str:
"""Print filename, line number and function name of a stack frame."""
- pass
+ filename = frame.f_code.co_filename
+ lineno = frame.f_lineno
+ funcname = frame.f_code.co_name
+ return f'{filename}:{lineno}, in {funcname}'
diff --git a/src/simpy/exceptions.py b/src/simpy/exceptions.py
index d45300e..beef1b2 100644
--- a/src/simpy/exceptions.py
+++ b/src/simpy/exceptions.py
@@ -31,4 +31,4 @@ class Interrupt(SimPyException):
@property
def cause(self) ->Optional[Any]:
"""The cause of the interrupt or ``None`` if no cause was provided."""
- pass
+ return self.args[0] if self.args else None
diff --git a/src/simpy/resources/base.py b/src/simpy/resources/base.py
index a7d0b96..ccedb56 100644
--- a/src/simpy/resources/base.py
+++ b/src/simpy/resources/base.py
@@ -58,7 +58,8 @@ class Put(Event, ContextManager['Put'], Generic[ResourceType]):
method is called automatically.
"""
- pass
+ if not self.triggered:
+ self.resource.put_queue.remove(self)
class Get(Event, ContextManager['Get'], Generic[ResourceType]):
@@ -104,7 +105,8 @@ class Get(Event, ContextManager['Get'], Generic[ResourceType]):
method is called automatically.
"""
- pass
+ if not self.triggered:
+ self.resource.get_queue.remove(self)
PutType = TypeVar('PutType', bound=Put)
@@ -152,7 +154,7 @@ class BaseResource(Generic[PutType, GetType]):
@property
def capacity(self) ->Union[float, int]:
"""Maximum capacity of the resource."""
- pass
+ return self._capacity
if TYPE_CHECKING:
def put(self) ->Put:
@@ -181,7 +183,7 @@ class BaseResource(Generic[PutType, GetType]):
:attr:`put_queue`, as long as the return value does not evaluate
``False``.
"""
- pass
+ raise NotImplementedError("The _do_put() method has to be implemented by subclasses.")
def _trigger_put(self, get_event: Optional[GetType]) ->None:
"""This method is called once a new put event has been created or a get
@@ -191,7 +193,12 @@ class BaseResource(Generic[PutType, GetType]):
calls :meth:`_do_put` to check if the conditions for the event are met.
If :meth:`_do_put` returns ``False``, the iteration is stopped early.
"""
- pass
+ idx = 0
+ while idx < len(self.put_queue):
+ put_event = self.put_queue[idx]
+ if not self._do_put(put_event):
+ break
+ idx += 1
def _do_get(self, event: GetType) ->Optional[bool]:
"""Perform the *get* operation.
@@ -204,7 +211,7 @@ class BaseResource(Generic[PutType, GetType]):
:attr:`get_queue`, as long as the return value does not evaluate
``False``.
"""
- pass
+ raise NotImplementedError("The _do_get() method has to be implemented by subclasses.")
def _trigger_get(self, put_event: Optional[PutType]) ->None:
"""Trigger get events.
@@ -216,4 +223,9 @@ class BaseResource(Generic[PutType, GetType]):
calls :meth:`_do_get` to check if the conditions for the event are met.
If :meth:`_do_get` returns ``False``, the iteration is stopped early.
"""
- pass
+ idx = 0
+ while idx < len(self.get_queue):
+ get_event = self.get_queue[idx]
+ if not self._do_get(get_event):
+ break
+ idx += 1
diff --git a/src/simpy/resources/container.py b/src/simpy/resources/container.py
index 00aa6de..fe7bce5 100644
--- a/src/simpy/resources/container.py
+++ b/src/simpy/resources/container.py
@@ -77,16 +77,16 @@ class Container(base.BaseResource):
@property
def level(self) ->ContainerAmount:
"""The current amount of the matter in the container."""
- pass
+ return self._level
if TYPE_CHECKING:
def put(self, amount: ContainerAmount) ->ContainerPut:
"""Request to put *amount* of matter into the container."""
- pass
+ return ContainerPut(self, amount)
def get(self, amount: ContainerAmount) ->ContainerGet:
"""Request to get *amount* of matter out of the container."""
- pass
+ return ContainerGet(self, amount)
else:
put = BoundClass(ContainerPut)
get = BoundClass(ContainerGet)
diff --git a/src/simpy/resources/resource.py b/src/simpy/resources/resource.py
index 2c4f6dd..fa35618 100644
--- a/src/simpy/resources/resource.py
+++ b/src/simpy/resources/resource.py
@@ -70,6 +70,15 @@ class Request(base.Put):
resource: Resource
usage_since: Optional[SimTime] = None
+ def __init__(self, resource: Resource):
+ super().__init__(resource)
+ self.resource = resource
+ self.usage_since = None
+
+ def __enter__(self):
+ self.usage_since = self.env.now
+ return self
+
def __exit__(self, exc_type: Optional[Type[BaseException]], exc_value:
Optional[BaseException], traceback: Optional[TracebackType]
) ->Optional[bool]:
@@ -90,6 +99,13 @@ class Release(base.Get):
"""The request (:class:`Request`) that is to be released."""
super().__init__(resource)
+ def __call__(self):
+ if self.request in self.resource.users:
+ self.resource.users.remove(self.request)
+ self.succeed()
+ else:
+ self.fail(ValueError("This request is not in the resource's users."))
+
class PriorityRequest(Request):
"""Request the usage of *resource* with a given *priority*. If the
@@ -138,7 +154,10 @@ class SortedQueue(list):
Raise a :exc:`RuntimeError` if the queue is full.
"""
- pass
+ if self.maxlen is not None and len(self) >= self.maxlen:
+ raise RuntimeError("Queue is full")
+ super().append(item)
+ self.sort(key=lambda x: x.key)
class Resource(base.BaseResource):
@@ -168,7 +187,7 @@ class Resource(base.BaseResource):
@property
def count(self) ->int:
"""Number of users currently using the resource."""
- pass
+ return len(self.users)
if TYPE_CHECKING:
def request(self) ->Request:
diff --git a/src/simpy/resources/store.py b/src/simpy/resources/store.py
index 5875e6d..379e325 100644
--- a/src/simpy/resources/store.py
+++ b/src/simpy/resources/store.py
@@ -73,11 +73,11 @@ class Store(base.BaseResource):
def put(self, item: Any) ->StorePut:
"""Request to put *item* into the store."""
- pass
+ return StorePut(self, item)
def get(self) ->StoreGet:
"""Request to get an *item* out of the store."""
- pass
+ return StoreGet(self)
else:
put = BoundClass(StorePut)
get = BoundClass(StoreGet)
@@ -111,6 +111,31 @@ class PriorityStore(Store):
"""
+ def __init__(self, env: Environment, capacity: Union[float, int]=float('inf')):
+ super().__init__(env, capacity)
+ self.items = [] # Use a list as a heap
+
+ if TYPE_CHECKING:
+ def put(self, item: Any) -> StorePut:
+ """Request to put *item* into the store."""
+ return StorePut(self, item)
+
+ def get(self) -> StoreGet:
+ """Request to get the highest priority *item* from the store."""
+ return StoreGet(self)
+ else:
+ put = BoundClass(StorePut)
+ get = BoundClass(StoreGet)
+
+ def _do_put(self, event: StorePut) -> None:
+ if len(self.items) < self.capacity:
+ heappush(self.items, event.item)
+ event.succeed()
+
+ def _do_get(self, event: StoreGet) -> None:
+ if self.items:
+ event.succeed(heappop(self.items))
+
class FilterStore(Store):
"""Resource with *capacity* slots for storing arbitrary objects supporting
@@ -139,6 +164,13 @@ class FilterStore(Store):
) ->FilterStoreGet:
"""Request to get an *item*, for which *filter* returns ``True``,
out of the store."""
- pass
+ return FilterStoreGet(self, filter)
else:
get = BoundClass(FilterStoreGet)
+
+ def _do_get(self, event: FilterStoreGet) -> None:
+ for item in self.items:
+ if event.filter(item):
+ self.items.remove(item)
+ event.succeed(item)
+ break
diff --git a/src/simpy/rt.py b/src/simpy/rt.py
index 9d99392..e3c068c 100644
--- a/src/simpy/rt.py
+++ b/src/simpy/rt.py
@@ -31,14 +31,14 @@ class RealtimeEnvironment(Environment):
@property
def factor(self) ->float:
"""Scaling factor of the real-time."""
- pass
+ return self._factor
@property
def strict(self) ->bool:
"""Running mode of the environment. :meth:`step()` will raise a
:exc:`RuntimeError` if this is set to ``True`` and the processing of
events takes too long."""
- pass
+ return self._strict
def sync(self) ->None:
"""Synchronize the internal time with the current wall-clock time.
@@ -48,7 +48,8 @@ class RealtimeEnvironment(Environment):
calling :meth:`run()` or :meth:`step()`.
"""
- pass
+ self.real_start = monotonic()
+ self.env_start = self._now
def step(self) ->None:
"""Process the next event after enough real-time has passed for the
@@ -59,4 +60,17 @@ class RealtimeEnvironment(Environment):
the event is processed too slowly.
"""
- pass
+ try:
+ evt_time = self.peek()
+ except EmptySchedule:
+ return
+
+ real_time = monotonic()
+ expected_real_time = self.real_start + (evt_time - self.env_start) / self._factor
+
+ if real_time < expected_real_time:
+ sleep(expected_real_time - real_time)
+ elif self._strict and real_time > expected_real_time:
+ raise RuntimeError(f'Simulation too slow: {real_time - expected_real_time:.3f} seconds late')
+
+ super().step()
diff --git a/src/simpy/util.py b/src/simpy/util.py
index 5e3a81a..bb287ec 100644
--- a/src/simpy/util.py
+++ b/src/simpy/util.py
@@ -33,7 +33,14 @@ def start_delayed(env: Environment, generator: ProcessGenerator, delay: SimTime
Raise a :exc:`ValueError` if ``delay <= 0``.
"""
- pass
+ if delay <= 0:
+ raise ValueError("delay must be > 0")
+
+ def delayed_process():
+ yield env.timeout(delay)
+ yield from generator
+
+ return env.process(delayed_process())
def subscribe_at(event: Event) ->None:
@@ -45,4 +52,11 @@ def subscribe_at(event: Event) ->None:
Raise a :exc:`RuntimeError` if ``event`` has already occurred.
"""
- pass
+ if event.triggered:
+ raise RuntimeError("Cannot subscribe to an event that has already occurred")
+
+ def interrupt_callback(event):
+ import simpy
+ simpy.exceptions.Interrupt(event.value)
+
+ event.callbacks.append(interrupt_callback)