Skip to content

schedule_event silently drops inline lambda callbacks before execution #3319

@falloficarus22

Description

@falloficarus22

Describe the bug
silent acceptance + later no-op due to weakref.

Expected behavior
schedule_event(lambda ...) should raise immediately with a clear error.

To Reproduce

from mesa import Model

m = Model()
state = {"x": 0}

m.schedule_event(lambda: state.__setitem__("x", state["x"] + 1), at=1.0)
m.run_for(2.0)

print(state["x"])  # observed: 0, expected: 1

Reproduction steps:

  1. Create a Model.
  2. Schedule an event with an inline lambda using at=... (or after=...).
  3. Advance time with run_for(...).
  4. Observe that side effects from the lambda do not occur.

Additional context

  • This appears related to event callbacks being stored via weak references in mesa.time.events.Event.
  • Named functions with a strong reference execute as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions