-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Model._event_generators grows unbounded #3313
Copy link
Copy link
Closed
Labels
bugRelease notes labelRelease notes label
Description
Describe the bug
Model._event_generators continues to grow while running a model, and also will contain generators that are exhausted. It is a minor bug, but worth addressing at some point. But since a generator also holds a hard ref to the callable, it might, for example, prevent agents from being garbage collected.
Expected behavior
Whenever a generator is exhausted (or stopped?), it should remove itself from model._event_generators.
proposed direction for fix
There are a couple of directions:
- Turn
._event_generatorsinto a set, and whenever a generator is exhausted, it removes itself from this set. The only function of_event_generatorsis to serve as a hard ref to generators, so ordering does not matter. This fix would also imply that the responsibility of adding a generator toschedule_recurringshould move fromschedule_recurringinto theEventGeneratorclass, so all instances are in the set. - Make it the responsibility of the caller of
schedule_recurringto maintain a hard ref to the generator. This is tricky for users, so less ideal. - To reduce the severity of the leak, we should consider turning self.function into a weakref similar to how it is done for
Event, and if the ref becomes None, this should automagically stop the generator.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugRelease notes labelRelease notes label