优化代码

This commit is contained in:
2018-03-08 18:11:48 +08:00
parent 9717328795
commit cf08bfcd7e
+7 -5
View File
@@ -47,8 +47,10 @@ def format_cmd(cmd):
if __name__ == "__main__": if __name__ == "__main__":
if os.path.exists("/var/run/price/price.sys.stop"): user_home = os.path.expanduser('~')
os.remove("/var/run/price/price.sys.stop") lock_file = user_home + "/price.sys.stop"
if os.path.exists(lock_file):
os.remove(lock_file)
pro_num = config.get_worker_num() pro_num = config.get_worker_num()
pool = multiprocessing.Pool(processes=pro_num) pool = multiprocessing.Pool(processes=pro_num)
for pid in range(0, pro_num): for pid in range(0, pro_num):
@@ -56,11 +58,11 @@ if __name__ == "__main__":
pool.close() pool.close()
logger.info("均价系统启动成功") logger.info("均价系统启动成功")
while True: while True:
if os.path.exists("/var/run/price/price.sys.stop"): if os.path.exists(lock_file):
pool.terminate() pool.terminate()
break break
else: else:
time.sleep(3) time.sleep(3)
if os.path.exists("/var/run/price/price.sys.stop"): if os.path.exists(lock_file):
os.remove("/var/run/price/price.sys.stop") os.remove(lock_file)
pool.join() pool.join()