Skip to content
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

Fix cancellation of file save operation #241

Merged
merged 2 commits into from
Mar 4, 2024
Merged
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
11 changes: 8 additions & 3 deletions jupyter_collaboration/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,14 @@ async def _maybe_save_document(self, saving_document: asyncio.Task | None) -> No
if saving_document is not None and not saving_document.done():
# the document is being saved, cancel that
saving_document.cancel()
dlqqq marked this conversation as resolved.
Show resolved Hide resolved
await saving_document

# save after X seconds of inactivity
await asyncio.sleep(self._save_delay)
# all async code (i.e. await statements) must be part of this try/except block
# because this coroutine is run in a cancellable task and cancellation is handled here

try:
# save after X seconds of inactivity
await asyncio.sleep(self._save_delay)

self.log.info("Saving the content from room %s", self._room_id)
await self._file.maybe_save_content(
{
Expand All @@ -253,6 +255,9 @@ async def _maybe_save_document(self, saving_document: asyncio.Task | None) -> No

self._emit(LogLevel.INFO, "save", "Content saved.")

except asyncio.CancelledError:
dlqqq marked this conversation as resolved.
Show resolved Hide resolved
return

except OutOfBandChanges:
self.log.info("Out-of-band changes. Overwriting the content in room %s", self._room_id)
try:
Expand Down
Loading