From 13ab981c5998deade9fedae80fa5e31d6f7078dc Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Sat, 21 Jan 2023 13:40:41 +0000 Subject: [PATCH] introduce back delay --- backend/server.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/server.py b/backend/server.py index cca3e2a..e58d805 100644 --- a/backend/server.py +++ b/backend/server.py @@ -810,20 +810,24 @@ import pickle def save_games(): global save_lock if not save_lock: + sio.sleep(2) with open('games.pickle', 'wb') as f: pickle.dump([g for g in games if g.started], f) save_games() if __name__ == '__main__': if os.path.exists('games.pickle'): - with open('games.pickle', 'rb') as file: - games = pickle.load(file) - for g in games: - for p in g.players: - if p.sid != 'bot': - sio.start_background_task(p.disconnect) - else: - sio.start_background_task(p.bot_spin) + try: + with open('games.pickle', 'rb') as file: + games = pickle.load(file) + for g in games: + for p in g.players: + if p.sid != 'bot': + sio.start_background_task(p.disconnect) + else: + sio.start_background_task(p.bot_spin) + except: + pass sio.start_background_task(save_games) sio.start_background_task(pool_metrics) eventlet.wsgi.server(eventlet.listen(('', 5001)), CustomProxyFix(app))