def safeiter(it, cleanup=None, ignore_errors=True):
 def next():
  while True:
   try:
    return next(it)
   except StopIteration:
    raise
   except:
    traceback.print_exc()
 it = iter(it)
 while True:
  (yield next())

def safeiter ( it , cleanup = None , ignore_errors = True ) : def next ( ) : while True : try : return next ( it ) except StopIteration : raise except : traceback . print_exc ( ) it = iter ( it ) while True : ( yield next ( ) )
makes an iterator safe by ignoring the exceptions occured during the iteration .