Skip to content

Commit

Permalink
WebHost: move atexit saving to end of room hosting function (Archipel…
Browse files Browse the repository at this point in the history
  • Loading branch information
Berserker66 authored and sflavelle committed Jun 20, 2024
1 parent 1d949be commit d7a6dec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions MultiServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def init_save(self, enabled: bool = True):
self.logger.exception(e)
self._start_async_saving()

def _start_async_saving(self):
def _start_async_saving(self, atexit_save: bool = True):
if not self.auto_saver_thread:
def save_regularly():
# time.time() is platform dependent, so using the expensive datetime method instead
Expand All @@ -532,8 +532,9 @@ def get_datetime_second():
self.auto_saver_thread = threading.Thread(target=save_regularly, daemon=True)
self.auto_saver_thread.start()

import atexit
atexit.register(self._save, True) # make sure we save on exit too
if atexit_save:
import atexit
atexit.register(self._save, True) # make sure we save on exit too

def get_save(self) -> dict:
self.recheck_hints()
Expand Down
3 changes: 2 additions & 1 deletion WebHostLib/customserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def init_save(self, enabled: bool = True):
savegame_data = Room.get(id=self.room_id).multisave
if savegame_data:
self.set_save(restricted_loads(Room.get(id=self.room_id).multisave))
self._start_async_saving()
self._start_async_saving(atexit_save=False)
threading.Thread(target=self.listen_to_db_commands, daemon=True).start()

@db_session
Expand Down Expand Up @@ -278,6 +278,7 @@ async def start_room(room_id):
raise
finally:
try:
ctx._save()
with (db_session):
# ensure the Room does not spin up again on its own, minute of safety buffer
room = Room.get(id=room_id)
Expand Down

0 comments on commit d7a6dec

Please sign in to comment.