Skip to content

Instantly share code, notes, and snippets.

@SweiLz
Created March 28, 2022 03:17
Show Gist options
  • Save SweiLz/e541080db5da37b6e9fdfd6f404c5389 to your computer and use it in GitHub Desktop.
Save SweiLz/e541080db5da37b6e9fdfd6f404c5389 to your computer and use it in GitHub Desktop.
Software Restart in Python
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