From 6ae548757afe1abeaeef28501d7974f07a51ac79 Mon Sep 17 00:00:00 2001 From: zhiyang7 Date: Tue, 28 Dec 2021 09:18:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=BB=E5=8A=A1=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douzero/server/battle.py | 2 +- evaluate_server.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/douzero/server/battle.py b/douzero/server/battle.py index 70c720d..a8948bb 100644 --- a/douzero/server/battle.py +++ b/douzero/server/battle.py @@ -97,7 +97,7 @@ def battle_logic(baseline : Baseline, battle : Battle): def tick(): try: - battles = Battle.select().where(Battle.status == 0).order_by(Battle.id.desc()).limit(10) + battles = Battle.select().where(Battle.status == 0).order_by(Battle.id.asc()).limit(1) for battle in battles: battle.status = -1 battle.save() diff --git a/evaluate_server.py b/evaluate_server.py index 68f3159..91f7bca 100644 --- a/evaluate_server.py +++ b/evaluate_server.py @@ -1,5 +1,7 @@ import itertools import os +import time +import threading from peewee import JOIN @@ -19,9 +21,6 @@ Model.create_table() Battle.create_table() Baseline.create_table() -threadpool = ThreadPoolExecutor(1) - - EnvCard2RealCard = {3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: 'T', 11: 'J', 12: 'Q', 13: 'K', 14: 'A', 17: '2', 20: 'X', 30: 'D'} @@ -49,9 +48,17 @@ def upload(): model_file.save(path) Model.create(path=path, position=position,type=type,frame=frame,create_time=datetime.now()) Battle.create(challenger_path=path, challenger_position=position, status=0) - threadpool.submit(tick) return jsonify({'status': 0, 'message': 'success', 'result': ''}) +def start_runner(): + def start_loop(): + while True: + tick() + time.sleep(10) + + thread = threading.Thread(target=start_loop) + thread.start() + @app.route('/battle_tick', methods=['POST']) def battle_tick(): tick()