deep-wine-runner/updatekiller.py
gfdgd_xi 1ec62bbf86
Some checks failed
Auto Building Wine Runner(rpm) / Explore-GitHub-Actions (push) Has been cancelled
Auto Building Wine Runner(deb) / Explore-GitHub-Actions (push) Has been cancelled
Building Wine Runner Off-line Pages(arm64) / Explore-GitHub-Actions (push) Has been cancelled
Building Wine Runner Off-line Pages(amd64) / Explore-GitHub-Actions (push) Has been cancelled
修复不存在TMPDIR/tmp文件夹时无法打开程序的问题
2024-08-11 09:26:24 +08:00

41 lines
1.1 KiB
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import sys
import os
import atexit
TMPDIR = os.getenv("TMPDIR")
if (TMPDIR == None):
TMPDIR = ""
PIDFILE = TMPDIR + '/tmp/deepin-wine-runner.pid'
if (not os.path.exists(TMPDIR + "/tmp")):
os.makedirs(TMPDIR + "/tmp")
#程序结束时清理pid
@atexit.register
def remove_pid():
'''程序结束时清理pid'''
with open(PIDFILE) as pidfile:
pidlst = pidfile.readlines()
pidlst.remove(str(PID)+'\n') #移除记录中的pid
with open(PIDFILE,'w') as pidfile:
pidfile.writelines(pidlst)
#更新时结束进程
def main():
for i in open(PIDFILE):
try:
os.kill(int(i),15)
except ProcessLookupError:
pass
## os.remove(PIDFILE) #因修复#I6ZRZX而注释
#当该程序被直接执行时执行结束进程操作。如果是导入的形式则只是记录pid
if __name__ == '__main__':
sys.exit(main())
else:
#获取进程pid用于更新时结束进程
PID = os.getpid()
with open(PIDFILE,'a') as pidfile:
print(PID,file=pidfile) #使用print可以在行末输出换行符而且可以省去类型转换