diff --git a/game/persistency.py b/game/persistency.py index 4520b021..9b982407 100644 --- a/game/persistency.py +++ b/game/persistency.py @@ -1,12 +1,13 @@ from __future__ import annotations import logging -import os import pickle import shutil from pathlib import Path from typing import Optional, TYPE_CHECKING +from game.profiling import logged_duration + if TYPE_CHECKING: from game import Game @@ -54,14 +55,15 @@ def load_game(path: str) -> Optional[Game]: def save_game(game: Game) -> bool: - try: - with open(_temporary_save_file(), "wb") as f: - pickle.dump(game, f) - shutil.copy(_temporary_save_file(), game.savepath) - return True - except Exception: - logging.exception("Could not save game") - return False + with logged_duration("Saving game"): + try: + with open(_temporary_save_file(), "wb") as f: + pickle.dump(game, f) + shutil.copy(_temporary_save_file(), game.savepath) + return True + except Exception: + logging.exception("Could not save game") + return False def autosave(game: Game) -> bool: