39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import time
|
|
import os
|
|
import subprocess
|
|
|
|
duration = 10 * 6000 # 总持续时间,单位为秒
|
|
interval = 1 # 循环间隔,单位为秒
|
|
iterations = duration // interval # 循环次数
|
|
server_status_fd_path = "/Users/erwin/SERVER_STATUS_FD"
|
|
|
|
if not os.path.exists(server_status_fd_path):
|
|
try:
|
|
with open(server_status_fd_path, "w") as f:
|
|
print("文件已创建")
|
|
f.close()
|
|
except Exception as e:
|
|
print(str(e))
|
|
|
|
try:
|
|
subprocess.run("kill -2 59638", shell=True)
|
|
except Exception as e:
|
|
print(str(e))
|
|
|
|
# 循环执行
|
|
for i in range(iterations):
|
|
time.sleep(interval)
|
|
print("执行代码,当前循环次数:", i + 1)
|
|
try:
|
|
with open(server_status_fd_path, "r") as f:
|
|
var = f.read().replace("\r", "").replace("\n", "").replace("\t", "")
|
|
if var == "STOP" or var == "":
|
|
subprocess.run("nohup /Users/erwin/wishpalv2/service/app/mix/cmd_local/cmd_local &", shell=True)
|
|
f.close()
|
|
break
|
|
f.close()
|
|
except Exception as e:
|
|
print(str(e))
|
|
|
|
# time.sleep(interval) # 等待指定的间隔时间
|