def monitored(total: int, name=None, message=None):
def decorator(f):<EOL><INDENT>nonlocal name<EOL>monitor_index = list(inspect.signature(f).parameters.keys()).index('<STR_LIT>')<EOL>if name is None:<EOL><INDENT>name=f.__name__<EOL><DEDENT>@wraps(f)<EOL>def wrapper(*args, **kargs):<EOL><INDENT>if len(args) > monitor_index:<EOL><INDENT>monitor = args[monitor_index]<EOL><DEDENT>elif '<STR_LIT>' in kargs:<EOL><INDENT>monitor = kargs['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>monitor = kargs['<STR_LIT>'] = NullMonitor()<EOL><DEDENT>with monitor.task(total, name, message):<EOL><INDENT>f(*args, **kargs)<EOL><DEDENT><DEDENT>return wrapper<EOL><DEDENT>return decorator<EOL>
Decorate a function to automatically begin and end a task on the progressmonitor.
The function must have a parameter called 'monitor'