Open leopd opened 4 years ago
I was looking for exactly this. I want to enable profiling, based on a boolean flag.
Do you plan to change the flag in code or at runtime? That is, do you want to go into the code and change the flag for profiling on/off vs have a command-line argument that does this? Because the implementations are different.
If you want to do it at runtime, then an argument in the decorator won't work. Because the decorator is evaluated (executed) when the code is loaded, on import, which generally happens before your code runs and starts looking at argparse
etc.
Which is all to say that something like this won't worok:
@timebudget(quiet=is_profiling_enabled)
def my_func():
pass
if __name__ == "__main__":
is_profiling_enabled = parse_setup_arguments()
Yes. I want to do something like this.
Is there an alternative way of achieving the same?
It looks like you should be able to annotate a funciton like
@timebudget(quiet=False)
but this doesn't work.