#!/usr/bin/env python # Run this, and press Ctrl-C before the socket times out. The innermost # error handler won't trigger import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind(('', 1234)) s.settimeout(10) try: try: print "The Meaning of Life." data = s.recv(1024) except: print 'This is the first except block' except KeyboardInterrupt: print 'This is the second except block' print 'finished'