Created
November 8, 2018 16:38
-
-
Save Lulzx/5c35274591b79e819ca9d7d4b1eacaf2 to your computer and use it in GitHub Desktop.
kill me
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 os | |
import sys | |
import signal | |
import subprocess | |
currentPID = os.getpid() | |
if 'pid' not in os.listdir(): | |
with open('pid', mode='w') as f: | |
print(str(currentPID), file=f) | |
else: | |
with open('pid', mode='r') as f: | |
try: | |
os.kill(int(f.read()), signal.SIGTERM) | |
print("Terminating previous instance of " + | |
os.path.realpath(__file__)) | |
except ProcessLookupError: | |
subprocess.run(['rm', 'pid']) | |
with open('pid', mode='w') as f: | |
print(str(currentPID), file=f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment