Makes an iterator safe by ignoring the exceptions occurred during the iteration.
(it, cleanup=None, ignore_errors=True)
| 727 | |
| 728 | |
| 729 | def safeiter(it, cleanup=None, ignore_errors=True): |
| 730 | """Makes an iterator safe by ignoring the exceptions occurred during the iteration.""" |
| 731 | |
| 732 | def next(): |
| 733 | while True: |
| 734 | try: |
| 735 | return next(it) |
| 736 | except StopIteration: |
| 737 | raise |
| 738 | except: |
| 739 | traceback.print_exc() |
| 740 | |
| 741 | it = iter(it) |
| 742 | while True: |
| 743 | yield next() |
| 744 | |
| 745 | |
| 746 | def safewrite(filename, content): |