I fail to see how this could break. rupture.sample_number_of_occurrences() returns a number, right? So or the xrange succeeds or it break immediately, not even an index is generated. Probably you want

        try:
            for i, rupture in enumerate(source.iter_ruptures(tom)):
                for _ in xrange(rupture.sample_number_of_occurrences()):
                    yield rupture
        except Exception, err:
             msg = 'An error occurred with rupture id=%s. Error: %s'