Skip to content

Commit aff427f

Browse files
committed
fix empty notebooks after room restart
1 parent 77e4852 commit aff427f

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

jupyter_server_documents/rooms/yroom.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -701,14 +701,13 @@ def stop(self, close_code: int = 1001, immediately: bool = False):
701701
# Otherwise, stop the file API.
702702
self.file_api.stop()
703703

704-
# Clear the YDoc, saving beforehand unless `immediately=True`
705-
if immediately:
706-
self._clear_ydoc()
707-
else:
704+
# Clear the YDoc, saving the previous content unless `immediately=True`
705+
if not immediately:
706+
prev_jupyter_ydoc = self._jupyter_ydoc
708707
self._loop.create_task(
709-
self._save_then_clear_ydoc()
708+
self.file_api.save(prev_jupyter_ydoc)
710709
)
711-
710+
self._clear_ydoc()
712711
self._stopped = True
713712

714713

@@ -725,24 +724,14 @@ def _clear_ydoc(self):
725724
)
726725

727726

728-
async def _save_then_clear_ydoc(self):
729-
"""
730-
Saves the JupyterYDoc, then calls `self._clear_ydoc()`.
731-
732-
This can be run safely in the background because the FileAPI uses a
733-
lock to prevent overlapping reads & writes to a single file.
734-
"""
735-
await self.file_api.save(self._jupyter_ydoc)
736-
self._clear_ydoc()
737-
738-
739727
@property
740728
def stopped(self) -> bool:
741729
"""
742730
Returns whether the room is stopped.
743731
"""
744732
return self._stopped
745733

734+
746735
@property
747736
def updated(self) -> bool:
748737
"""
@@ -755,6 +744,7 @@ def updated(self) -> bool:
755744
"""
756745
return self._updated
757746

747+
758748
def restart(self, close_code: int = 1001, immediately: bool = False):
759749
"""
760750
Restarts the YRoom. This method re-initializes & reloads the YDoc,

0 commit comments

Comments
 (0)