class documentation

class time_limited: (source)

View In Hierarchy

Yield items from *iterable* until *limit_seconds* have passed. If the time limit expires before all items have been yielded, the ``timed_out`` parameter will be set to ``True``. >>> from time import sleep >>> def generator(): ... yield 1 ... yield 2 ... sleep(0.2) ... yield 3 >>> iterable = time_limited(0.1, generator()) >>> list(iterable) [1, 2] >>> iterable.timed_out True Note that the time is checked before each item is yielded, and iteration stops if the time elapsed is greater than *limit_seconds*. If your time limit is 1 second, but it takes 2 seconds to generate the first item from the iterable, the function will run for 2 seconds and not yield anything.

Method __init__ Undocumented
Method __iter__ Undocumented
Method __next__ Undocumented
Instance Variable limit_seconds Undocumented
Instance Variable timed_out Undocumented
Instance Variable _iterable Undocumented
Instance Variable _start_time Undocumented
def __init__(self, limit_seconds, iterable): (source)

Undocumented

def __iter__(self): (source)

Undocumented

def __next__(self): (source)

Undocumented

limit_seconds = (source)

Undocumented

timed_out: bool = (source)

Undocumented

_iterable = (source)

Undocumented

_start_time = (source)

Undocumented