import os import time def server_run(port, command): # 设置服务缓存时间(防止更新服务产生冲突) # server = os.popen("lsof -i:{}".format(port)).readlines() # if not server: print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), "即将启动{}端口服务".format(port)) # 启动服务 os.popen(command) while True: time.sleep(5) e2cc_app_server = os.popen("lsof -i:10116").readlines() if not e2cc_app_server: # server_run(10116, "gunicorn -D -c gconfig.py E2CC_server:app product") server_run(10116, "nohup python E2CC_server.py product > logs/temp.log 2>&1") # server_run(10116, "gunicorn -D -c gconfig.py E2CC_server:app test")