def parse_duration(time_str, log=logging.getLogger('{}.time_utils'.format(LOG_PREFIX))):
    'Parse a time string e.g. (2h13m) into a timedelta object\n    https://stackoverflow.com/questions/4628122/how-to-construct-a-timedelta-object-from-a-simple-string\n\n    Arguments:\n        - time_str: A string identifying a duration. Use\n            - d: days\n            - h: hours\n            - m: minutes\n            - s: seconds\n          All options are optional but at least one needs to be supplied. Float\n          values are allowed (e.g. "1.5d" is the same as "1d12h"). Spaces\n          between each field is allowed. Examples:\n              - 1h 30m 45s\n              - 1h05s\n              - 55h 59m 12s\n        - log: optional, logger object for logging a warning if the passed in\n        string is not parsable. A "time_utils" logger will be used if not\n        supplied.\n\n    Returns:\n        A ``datetime.timedelta`` object representing the supplied time duration\n        or ``None`` if ``time_str`` cannot be parsed.\n    '
    parts = duration_regex.match(time_str)
    if (parts is None):
        log.warn("Could not parse any time information from '{}'. Examples of valid strings: '8h', '2d8h5m20s', '2m 4s'".format(time_str))
        return None
    else:
        time_params = {name: float(param) for (name, param) in parts.groupdict().items() if param}
        return timedelta(**time_params)
Parse a time string e.g. (2h13m) into a timedelta object
https://stackoverflow.com/questions/4628122/how-to-construct-a-timedelta-object-from-a-simple-string

Arguments:
    - time_str: A string identifying a duration. Use
        - d: days
        - h: hours
        - m: minutes
        - s: seconds
      All options are optional but at least one needs to be supplied. Float
      values are allowed (e.g. "1.5d" is the same as "1d12h"). Spaces
      between each field is allowed. Examples:
          - 1h 30m 45s
          - 1h05s
          - 55h 59m 12s
    - log: optional, logger object for logging a warning if the passed in
    string is not parsable. A "time_utils" logger will be used if not
    supplied.

Returns:
    A ``datetime.timedelta`` object representing the supplied time duration
    or ``None`` if ``time_str`` cannot be parsed.
def parse_duration(time_str, log=logging.getLogger('{}.time_utils'.format(LOG_PREFIX))):
    'Parse a time string e.g. (2h13m) into a timedelta object\n    https://stackoverflow.com/questions/4628122/how-to-construct-a-timedelta-object-from-a-simple-string\n\n    Arguments:\n        - time_str: A string identifying a duration. Use\n            - d: days\n            - h: hours\n            - m: minutes\n            - s: seconds\n          All options are optional but at least one needs to be supplied. Float\n          values are allowed (e.g. "1.5d" is the same as "1d12h"). Spaces\n          between each field is allowed. Examples:\n              - 1h 30m 45s\n              - 1h05s\n              - 55h 59m 12s\n        - log: optional, logger object for logging a warning if the passed in\n        string is not parsable. A "time_utils" logger will be used if not\n        supplied.\n\n    Returns:\n        A ``datetime.timedelta`` object representing the supplied time duration\n        or ``None`` if ``time_str`` cannot be parsed.\n    '
    parts = duration_regex.match(time_str)
    if (parts is None):
        log.warn("Could not parse any time information from '{}'. Examples of valid strings: '8h', '2d8h5m20s', '2m 4s'".format(time_str))
        return None
    else:
        time_params = {name: float(param) for (name, param) in parts.groupdict().items() if param}
        return timedelta(**time_params)