add save lock
This commit is contained in:
parent
8e745fa796
commit
ec48007377
@ -56,15 +56,19 @@ def send_to_debug(error):
|
|||||||
if g.debug or any((p.is_admin() for p in g.players)):
|
if g.debug or any((p.is_admin() for p in g.players)):
|
||||||
sio.emit('chat_message', room=g.name, data={'color': f'red','text':json.dumps({'ERROR':error}), 'type':'json'})
|
sio.emit('chat_message', room=g.name, data={'color': f'red','text':json.dumps({'ERROR':error}), 'type':'json'})
|
||||||
|
|
||||||
|
save_lock = False
|
||||||
def bang_handler(func):
|
def bang_handler(func):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper_func(*args, **kwargs):
|
def wrapper_func(*args, **kwargs):
|
||||||
|
global save_lock
|
||||||
|
save_lock = True
|
||||||
try:
|
try:
|
||||||
func(*args, **kwargs)
|
func(*args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
send_to_debug(traceback.format_exc())
|
send_to_debug(traceback.format_exc())
|
||||||
|
save_lock = False
|
||||||
return wrapper_func
|
return wrapper_func
|
||||||
|
|
||||||
def advertise_lobbies():
|
def advertise_lobbies():
|
||||||
@ -454,7 +458,7 @@ def chat_message(sid, msg, pl=None):
|
|||||||
while any((p for p in ses.game.players if p.name == bot.name)):
|
while any((p for p in ses.game.players if p.name == bot.name)):
|
||||||
bot = Player(f'AI_{random.randint(0,10)}', 'bot', bot=True)
|
bot = Player(f'AI_{random.randint(0,10)}', 'bot', bot=True)
|
||||||
ses.game.add_player(bot)
|
ses.game.add_player(bot)
|
||||||
bot.bot_spin()
|
sio.start_background_task(bot.bot_spin)
|
||||||
return
|
return
|
||||||
if '/replay' in msg and not '/replayspeed' in msg and not '/replaypov' in msg:
|
if '/replay' in msg and not '/replayspeed' in msg and not '/replaypov' in msg:
|
||||||
_cmd = msg.split()
|
_cmd = msg.split()
|
||||||
@ -804,9 +808,10 @@ discord_ci = '1059452581027532880'
|
|||||||
discord_cs = 'Mc8ZlMQhayzi1eOqWFtGHs3L0iXCzaEu'
|
discord_cs = 'Mc8ZlMQhayzi1eOqWFtGHs3L0iXCzaEu'
|
||||||
import pickle
|
import pickle
|
||||||
def save_games():
|
def save_games():
|
||||||
sio.sleep(2)
|
global save_lock
|
||||||
with open('games.pickle', 'wb') as f:
|
if not save_lock:
|
||||||
pickle.dump([g for g in games if g.started], f)
|
with open('games.pickle', 'wb') as f:
|
||||||
|
pickle.dump([g for g in games if g.started], f)
|
||||||
save_games()
|
save_games()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user