From 85c52207f2e78002e41f96e1dac46d07cf742719 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Mon, 6 May 2024 10:01:22 +0200 Subject: [PATCH 1/5] Start ystore in a task --- jupyter_collaboration/rooms.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/jupyter_collaboration/rooms.py b/jupyter_collaboration/rooms.py index d1e2a6bc..77b22ef7 100644 --- a/jupyter_collaboration/rooms.py +++ b/jupyter_collaboration/rooms.py @@ -21,6 +21,8 @@ class DocumentRoom(YRoom): """A Y room for a possibly stored document (e.g. a notebook).""" + _background_tasks: set[asyncio.Task] + def __init__( self, room_id: str, @@ -48,6 +50,7 @@ def __init__( self._cleaner: asyncio.Task | None = None self._saving_document: asyncio.Task | None = None self._messages: dict[str, asyncio.Lock] = {} + self._background_tasks = set() # Listen for document changes self._document.observe(self._on_document_change) @@ -100,7 +103,9 @@ async def initialize(self) -> None: # try to apply Y updates from the YStore for this document read_from_source = True if self.ystore is not None: - await self.ystore.started.wait() + if not self.ystore.started.is_set(): + self.create_task(self.ystore.start()) + await self.ystore.started.wait() try: await self.ystore.apply_updates(self.ydoc) self._emit( @@ -174,6 +179,11 @@ async def stop(self) -> None: self._document.unobserve() self._file.unobserve(self.room_id) + def create_task(self, aw): + task = asyncio.create_task(aw) + self._background_tasks.add(task) + task.add_done_callback(self._background_tasks.discard) + async def _broadcast_updates(self): # FIXME should be upstreamed try: From 24e8c18a052307adcad84c0229d15bcbaf43a45a Mon Sep 17 00:00:00 2001 From: David Brochart Date: Tue, 7 May 2024 11:44:51 +0200 Subject: [PATCH 2/5] Use YStore's start_lock --- jupyter_collaboration/rooms.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jupyter_collaboration/rooms.py b/jupyter_collaboration/rooms.py index 77b22ef7..f92a5727 100644 --- a/jupyter_collaboration/rooms.py +++ b/jupyter_collaboration/rooms.py @@ -103,9 +103,10 @@ async def initialize(self) -> None: # try to apply Y updates from the YStore for this document read_from_source = True if self.ystore is not None: - if not self.ystore.started.is_set(): - self.create_task(self.ystore.start()) - await self.ystore.started.wait() + async with self.ystore.start_lock: + if not self.ystore.started.is_set(): + self.create_task(self.ystore.start()) + await self.ystore.started.wait() try: await self.ystore.apply_updates(self.ydoc) self._emit( From 707fd0f009b452788a917632bbd243fcb04a5340 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Tue, 7 May 2024 22:39:28 +0200 Subject: [PATCH 3/5] Bump pycrdt-websocket>=0.13.4 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9e9c6cad..0898c0c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ classifiers = [ dependencies = [ "jupyter_server>=2.0.0,<3.0.0", "jupyter_ydoc>=2.0.0,<3.0.0", - "pycrdt-websocket>=0.13.2,<0.14.0", + "pycrdt-websocket>=0.13.4,<0.14.0", "jupyter_events>=0.10.0", "jupyter_server_fileid>=0.7.0,<1", "jsonschema>=4.18.0" From 29df39c53617a8d368a27af33354a912c223efc7 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Tue, 7 May 2024 22:55:08 +0200 Subject: [PATCH 4/5] Backport #305 (fix test start store) --- tests/conftest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 943e2172..5f5a6a62 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,7 +3,7 @@ from __future__ import annotations import json -from asyncio import Event, sleep +from asyncio import Event, create_task, sleep from datetime import datetime from typing import Any @@ -177,7 +177,8 @@ def rtc_create_SQLite_store(jp_serverapp): async def _inner(type: str, path: str, content: str) -> DocumentRoom: db = SQLiteYStore(path=f"{type}:{path}") - await db.start() + task = create_task(db.start()) + await db.started.wait() if type == "notebook": doc = YNotebook() From 02d0c05f1b56e16214399a4ec32e7260b82d6316 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Tue, 7 May 2024 23:04:30 +0200 Subject: [PATCH 5/5] Pin jupyterlab<4.2.0 in tests --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5a057b48..0745ab48 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: - name: Install dependencies run: | - pip install "jupyterlab>=4.0.0,<5" + pip install "jupyterlab>=4.0.0,<4.2.0" pip install -e . jlpm @@ -68,7 +68,7 @@ jobs: - name: Install dependencies run: | - pip install "jupyterlab>=4.0.0,<5" + pip install "jupyterlab>=4.0.0,<4.2.0" pip install -e . jlpm @@ -103,7 +103,7 @@ jobs: - name: Install the Python dependencies run: | - python -m pip install "jupyterlab>=4.0.0,<5" + python -m pip install "jupyterlab>=4.0.0,<4.2.0" pip install -e ".[test]" codecov - name: List installed packages @@ -216,7 +216,7 @@ jobs: mkdir test tar --strip-components=1 -zxvf *.tar.gz -C ./test cd test - python -m pip install "jupyterlab>=4.0.0,<5" + python -m pip install "jupyterlab>=4.0.0,<4.2.0" python -m pip install ".[test]" echo "::endgroup::"