Created
March 28, 2022 03:17
-
-
Save SweiLz/e541080db5da37b6e9fdfd6f404c5389 to your computer and use it in GitHub Desktop.
Software Restart in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import time | |
def restart(): | |
print(f"Restart >> argv:{sys.argv} executable:{sys.executable}") | |
os.execv(sys.executable, ['python'] + sys.argv) | |
try: | |
for i in range(5, 0, -1): | |
print(i) | |
time.sleep(1) | |
restart() | |
except KeyboardInterrupt: | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment