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

Start ystore in a task #302

Merged
merged 5 commits into from
May 7, 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
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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::"

Expand Down
13 changes: 12 additions & 1 deletion jupyter_collaboration/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -100,7 +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:
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(
Expand Down Expand Up @@ -174,6 +180,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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
Loading