It would vary as to how I would handle a TPK with much depending on what the PLAYERS seem to want to do. As a rule, however, I work VERY hard to avoid a true TPK, even when the idiots really have it coming to them. The simple reason why is that it isn't just THEIR game they're screwing up - they're ruining things for me as well. Since as the DM I am in just the right position to make a deus ex machina at least seem reasonable if not actually make it all work for the better I have no problems saving MY game by saving at least one PC from a TPK to keep my plots and such going.