Skip to content

WebHost: move atexit saving to end of room hosting function #3339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading