OpenQuizz
Une application de gestion des contenus pédagogiques
time_limited Class Reference

Public Member Functions

def __init__ (self, limit_seconds, iterable)
 
def __iter__ (self)
 
def __next__ (self)
 

Data Fields

 limit_seconds
 
 timed_out
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  limit_seconds,
  iterable 
)

Member Function Documentation

◆ __iter__()

def __iter__ (   self)

◆ __next__()

def __next__ (   self)

Field Documentation

◆ limit_seconds

limit_seconds

◆ timed_out

timed_out

The documentation for this class was generated from the following file: