class_docstr: Wrapper class to add timeout feature to synchronous iterators
  - timeout: timeout for next(). Default=ZERO_TIMEOUT i.e. no timeout or blocking calls to next. Updated using set_timeout() 
  - sentinel: the object returned by iterator when timeout happens
  - reset_on_next: if set to True, timeout is reset to the value of ZERO_TIMEOUT on each iteration
  
  TimeoutIterator uses a thread internally.
  The thread stops once the iterator exhausts or raises an exception during iteration.
  
  Any exceptions raised within the wrapped iterator are propagated as it is.
  Exception is raised when all elements generated by the actual iterator before exception have been consumed
  Timeout can be set dynamically before going for iteration
class_docstr_tok: ["Wrapper","class","to","add","timeout","feature","to","synchronous","iterators","-","timeout",":","timeout","for","next","(",")",".","Default=ZERO_TIMEOUT","i.e",".","no","timeout","or","blocking","calls","to","next",".","Updated","using","set_timeout","(",")","-","sentinel",":","the","object","returned","by","iterator","when","timeout","happens","-","reset_on_next",":","if","set","to","True",",","timeout","is","reset","to","the","value","of","ZERO_TIMEOUT","on","each","iteration","TimeoutIterator","uses","a","thread","internally",".","The","thread","stops","once","the","iterator","exhausts","or","raises","an","exception","during","iteration",".","Any","exceptions","raised","within","the","wrapped","iterator","are","propagated","as","it","is",".","Exception","is","raised","when","all","elements","generated","by","the","actual","iterator","before","exception","have","been","consumed","Timeout","can","be","set","dynamically","before","going","for","iteration"]
code: def __lookahead(self):
      try:
          while True:
              self._buffer.put(next(self._iterator))
              if self._interrupt:
                  raise StopIteration()
      except BaseException as e:
          if not isinstance(e, StopIteration):
              print(
                  "Generation Failed lookahead: %s %s %s"
                  % (str(e), type(e), self._whichi),
                  flush=True,
              )
          self._buffer.put(e)
  
file_path: h2ogpt/iterators/timeout_iterator.py
imports: import queue
  import asyncio
  import threading
  import traceback
label_desc: Use image node_id 8 for calling the TimeoutIterator obj's underlying member method code with example usage: obj.__lookahead() without return types