toil.lib.memoize¶
Attributes¶
Memoize a function result based on its parameters using this decorator. |
|
Functions¶
|
Like memoize, but guarantees that decorated function is only called once, even when multiple |
Parses an RFC 3339 ISO 8601 time in the UTC timezone. |
|
|
Variant of bool() that only accepts two possible string values. |
Module Contents¶
- toil.lib.memoize.memoize¶
Memoize a function result based on its parameters using this decorator.
For example, this can be used in place of lazy initialization. If the decorating function is invoked by multiple threads, the decorated function may be called more than once with the same arguments.
- toil.lib.memoize.MAT¶
- toil.lib.memoize.MRT¶
- toil.lib.memoize.sync_memoize(f)[source]¶
Like memoize, but guarantees that decorated function is only called once, even when multiple threads are calling the decorating function with multiple parameters.
- Parameters:
f (collections.abc.Callable[[MAT], MRT])
- Return type:
collections.abc.Callable[[MAT], MRT]
- toil.lib.memoize.parse_iso_utc(s)[source]¶
Parses an RFC 3339 ISO 8601 time in the UTC timezone.
Other timezones are not supported. Returns a timezone-aware UTC datetime object.
- Parameters:
s (str) – The ISO-formatted time
- Returns:
A timezone-aware UTC datetime object
- Raises:
ValueError – if the string is not in the correct format or is not in the UTC timezone.
- Return type:
>>> parse_iso_utc('2016-04-27T00:28:04.000Z') datetime.datetime(2016, 4, 27, 0, 28, 4, tzinfo=datetime.timezone.utc) >>> parse_iso_utc('2016-04-27T00:28:04Z') datetime.datetime(2016, 4, 27, 0, 28, 4, tzinfo=datetime.timezone.utc) >>> parse_iso_utc('2016-04-27T00:28:04X') Traceback (most recent call last): ... ValueError: Not a valid ISO datetime in UTC: 2016-04-27T00:28:04X