From 3feeb5724f236c3e0611c95e12ac61bf764f13dd Mon Sep 17 00:00:00 2001 From: "Bobby R. Bruce" Date: Tue, 17 Sep 2024 16:34:24 +0000 Subject: [PATCH] stdlib: Issue warn if func is a gen for exit_event (#1499) Addresses Issue #1492 --- src/python/gem5/simulate/simulator.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/python/gem5/simulate/simulator.py b/src/python/gem5/simulate/simulator.py index 3ca4f107b8..49dfac2bdf 100644 --- a/src/python/gem5/simulate/simulator.py +++ b/src/python/gem5/simulate/simulator.py @@ -357,6 +357,20 @@ class Simulator: # In instances where the user passes a lone function, the # function is called on every exit event of that type. Here # we convert the function into an infinite generator. + + # We check if the function is a generator. If it is we + # throw a warning as this is likely a mistake. + import inspect + + if inspect.isgeneratorfunction(value): + warn( + f"Function passed for '{key.value}' exit event " + "is not a generator but a function that returns " + "a generator. Did you mean to do this? (e.g., " + "did you mean `ExitEvent.EVENT : gen()` instead " + "of `ExitEvent.EVENT : gen`)" + ) + def function_generator(func: Callable): while True: yield func()