Skip to content

Commit 16b2675

Browse files
committed
Only allow one instance of the script at the time
1 parent 53f5234 commit 16b2675

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

kde-material-you-colors

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import argparse
66
import utils
77
from schemeconfigs import ThemeConfig
88
if __name__ == '__main__':
9+
#kill existing instance if found
10+
utils.kill_existing()
911
# Make sure the schemes path exists
1012
if not os.path.exists(utils.USER_SCHEMES_PATH):
1113
os.makedirs(utils.USER_SCHEMES_PATH)

utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,3 +875,13 @@ def timeout_set(time_s=3):
875875

876876
def timeout_reset():
877877
signal.alarm(0)
878+
879+
def kill_existing():
880+
get_pids=subprocess.check_output("ps -e -f | grep [/]usr/bin/kde-material-you-colors | awk '{print $2}'",
881+
shell=True, stderr=subprocess.PIPE,universal_newlines=True).strip().splitlines()
882+
current_pid = os.getpid()
883+
for pid in get_pids:
884+
pid = int(pid)
885+
if pid != current_pid:
886+
logging.debug(f"Found existing process with PID: '{pid}' killing...")
887+
subprocess.Popen("kill -9 "+str(pid),shell=True)

0 commit comments

Comments
 (0)