def stop_expired_slices():
    
    expired_slices = Slice.objects.filter(
        expiration_date__lte=datetime.now(), started=True)
    
    for slice in expired_slices:
        threadlocals.push_frame(user=slice.owner)
        try:
            slice.stop(slice.owner)
        except:
            logger.error(
                "Error stopping expired slice"
                " %s: %s" % (slice, traceback.format_exc()))
        threadlocals.pop_frame()
        try:
            send_mail(
                "Your slice %s expired." % slice,
                "Your slice %s has been stopped because it expired on %s."
                "Before you restart your slice, you will need to update the "
                "slice's expiration date." % (slice, slice.expiration_date),
                from_email=settings.DEFAULT_FROM_EMAIL,
                recipient_list=[slice.owner.email],
            )
        except:
            logger.error(
                "Error sending expired slice "
                "email to user: %s" % traceback.format_exc())
Find expired slices and stop them, sending an email to the owner.
dataset/ETHPy150Open fp7-ofelia/ocf/expedient/src/python/expedient/clearinghouse/slice/models.py/stop_expired_slices