timebudget icon indicating copy to clipboard operation
timebudget copied to clipboard

quiet=false doesn't work in annotation

Open leopd opened this issue 4 years ago • 3 comments

It looks like you should be able to annotate a funciton like @timebudget(quiet=False) but this doesn't work.

leopd avatar Apr 16 '20 00:04 leopd

I was looking for exactly this. I want to enable profiling, based on a boolean flag.

akash-suresh avatar May 09 '20 03:05 akash-suresh

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()

leopd avatar May 12 '20 18:05 leopd

Yes. I want to do something like this.

Is there an alternative way of achieving the same?

akash-suresh avatar May 13 '20 02:05 akash-suresh