I just used knockknock frequently in my previous research experiment. And I found it is inconvenient at this time if I want to use knockknock multiple times in my codebase. Because I need to maintain consistent sender function parameters in my code everywhere. And it is easy to leakage my personal security token (such as slack webhook_url). As a result, I propose to add a general decorator to handle these tricky things.
Property:
This general decorator can parse a config file to handle different sender function parameters.
The decorator can be silent when we are debugging our codebase. Since at the debug stage, we don't need verbose notification.
Separate the sender config in an independent config file can mitigate the risk of information leakage. (Just adding the config file into your .gitignore file.)
I finished the above properties. And I tested it on my personal desktop (Mac).
Below are some code examples:
Usage of general decorator
from knockknock import knockknock # general decorator is named as knockknock (like tqdm)
@knockknock(config_path='./', config_name='test.ini') # directly set your config path
def train_your_model(your_nicest_parameters):
import time
time.sleep(10)
return {'loss': 0.9} # Optional return value
@knockknock(config_path='./', config_name='test.ini') # convenient to use it multiple times in your codebase
def eval_your_model(your_nicest_parameters):
import time
time.sleep(10)
return {'acc': 0.9} # Optional return value
If `notification` is not set, it will be `True` by default. The config file must be started with the `knockknock` tag. And the `sender` determines the sender type. Other parameters are related to according sender function.
Hey all,
I just used knockknock frequently in my previous research experiment. And I found it is inconvenient at this time if I want to use knockknock multiple times in my codebase. Because I need to maintain consistent sender function parameters in my code everywhere. And it is easy to leakage my personal security token (such as slack webhook_url). As a result, I propose to add a general decorator to handle these tricky things.
Property:
.gitignore
file.)I finished the above properties. And I tested it on my personal desktop (Mac).
Below are some code examples:
@knockknock(config_path='./', config_name='test.ini') # directly set your config path def train_your_model(your_nicest_parameters): import time time.sleep(10) return {'loss': 0.9} # Optional return value
@knockknock(config_path='./', config_name='test.ini') # convenient to use it multiple times in your codebase def eval_your_model(your_nicest_parameters): import time time.sleep(10) return {'acc': 0.9} # Optional return value
train_your_model(None) eval_your_model(None)
[knockknock] sender=your_sender_type notification=True webhook_url=your_webhook_url channel=your_channel