Skip to content

Conversation

@dlqqq
Copy link
Collaborator

@dlqqq dlqqq commented May 21, 2025

Description

  • Closes Cannot shut down asyncio Queues in Python <3.13 #64
  • Replaces calls to asyncio.Queue.shutdown() with asyncio.Queue.put_nowait(None).
  • When either queue in YRoom and YRoomFileAPI receives an item of value None, the background task watching that queue will shut down.
  • Adds docstrings that clearly define this behavior for future developers.

Testing instructions

  • Create a new environment
  • Use python=3.10 and jupyterlab=4.4 (our extension still requires JL >=4.4)
  • Run jlpm dev:install
  • Start the server & open a text & notebook file
  • Verify that the server shuts down gracefully

Future work

@dlqqq dlqqq added the bug Something isn't working label May 21, 2025
Comment on lines -227 to -231
# Do nothing if content was not loaded first. This prevents overwriting
# the existing file with an empty JupyterYDoc.
if not (self._ydoc_content_loaded.is_set()):
return

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines were never called, since the _process_scheduled_saves() task always waits on the content to be loaded. Since the server won't stop until all of the background tasks are stopped, the content is always loaded before shutdown and we don't need to check its status.

We can add a way to cancel the initial content loading while the server is shutting down in a future PR. That change would only speed up server shutdown by 1-100 ms, so I don't think it's a priority for us right now.

@Zsailer
Copy link
Collaborator

Zsailer commented May 21, 2025

Thanks, @dlqqq ! Looks great. Pulled this PR down and tried it on Python 3.10. Works great.

@Zsailer Zsailer merged commit 2f9e661 into jupyter-ai-contrib:main May 21, 2025
2 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot shut down asyncio Queues in Python <3.13

2 participants