这很简单,希望可以对您有所帮助:
import timeimport pickleREGISTRY = Nonedef main(start=0): """Do some heavy work ...""" global REGISTRY a = start while 1: time.sleep(1) a += 1 print a REGISTRY = pickle.dumps(a)if __name__ == '__main__': print "To stop the script execution type CTRL-C" while 1: start = pickle.loads(REGISTRY) if REGISTRY else 0 try: main(start=start) except KeyboardInterrupt: resume = raw_input('If you want to continue type the letter c:') if resume != 'c': break运行示例:
$ python test.pyTo stop the script execution type CTRL-C123^CIf you want to continue type the letter c:c456789^CIf you want to continue type the letter c:$ python test.py



