catch errors within generator and continue afterwards
问题 I have an iterator which is supposed to run for several days. I want errors to be caught and reported, and then I want the iterator to continue. Or the whole process can start over. Here's the function: def get_units(self, scraper): units = scraper.get_units() i = 0 while True: try: unit = units.next() except StopIteration: if i == 0: log.error("Scraper returned 0 units", {'scraper': scraper}) break except: traceback.print_exc() log.warning("Exception occurred in get_units", extra={'scraper':