#coding=utf8
import time
import sys
import os
def restart_program():
"""Restarts the current program.
Note: this function does not return. Any cleanup action (like
saving data) must be done before calling this function."""
python = sys.executable
os.execl(python, python, * sys.argv)
if __name__ == "__main__":
print 'start...'
answer = raw_input("Do you want to restart this program ? ")
if answer.strip() in "y Y yes Yes YES".split():
restart_program()
print "3秒后,程序将结束..."
time.sleep(3)
运行结果如下:
[root@localhost sinatpy2.x]# python restart_self.py
start...
Do you want to restart this program ? y
start...
Do you want to restart this program ? y
start...
Do you want to restart this program ? y
start...
Do you want to restart this program ? y
start...
Do you want to restart this program ? yes
start...
Do you want to restart this program ? n
3秒后,程序将结束...
[root@localhost sinatpy2.x]#
阅读(2057) | 评论(0) | 转发(0) |