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

Migrate JsonRPCServer.start_tcp and JsonRPCServer.start_ws to high level asyncio APIs #507

Merged
merged 6 commits into from
Oct 28, 2024

Conversation

alcarney
Copy link
Collaborator

@alcarney alcarney commented Oct 27, 2024

This PR completes the migration of the server-side of pygls to the higher level asyncio APIs
Closes #334

start_tcp

  • Since asyncio.start_server gives us a reader, writer pair it's enough to reuse the run_async method from the pygls.io_ module.

start_ws

  • This moves the WebSocketTransportAdapter into pygls.io_ and a new run_websocket function, allowing the websocket main loop to be shared between client and server code
  • This PR also takes the opportunity to migrate to the new websockets.asyncio API

It's also worth noting that the test suite now includes the values of --lsp-runtime and --lsp-transport in the header pytest prints at the start of a test run

$ pytest
=========================================== test session starts ===========================================
platform linux -- Python 3.13.0, pytest-8.3.3, pluggy-1.5.0
rootdir: /var/home/alex/Projects/openlawlibrary/pygls/main
configfile: pyproject.toml
plugins: cov-5.0.0, asyncio-0.24.0
asyncio: mode=Mode.AUTO, default_loop_scope=None
pygls: runtime='cpython', transport='stdio'         <-- NEW!
collected 222 items                                                                                                

Code review checklist (for code reviewer to complete)

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR)
  • Title summarizes what is changing
  • Commit messages are meaningful (see this for details)
  • Tests have been included and/or updated, as appropriate
  • Docstrings have been included and/or updated, as appropriate
  • Standalone docs have been updated accordingly

Automated linters

You can run the lints that are run on CI locally with:

poetry install --all-extras --with dev
poetry run poe lint

This commit adds a `run_websocket` function to the `pygls.io_` module,
allowing for the websocket based main loop to be shared between client
and server.

This also takes the opportunity to migrate the server side code to the
new `websockets.asyncio` API.

Finally, now that none of the `start_xx` methods use the lower-level
asyncio APIs the explicit `loop` argument and related code has been removed.
This would lead to the task responsible for closing the websocket
connection being cancelled, resulting in the client and server
deadlocking each waiting for the other to close the conneciton.
Copy link
Collaborator

@tombh tombh left a comment

Choose a reason for hiding this comment

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

THIS PR <-- GREAT!

@alcarney
Copy link
Collaborator Author

Thanks!

@alcarney alcarney merged commit 9b7d50d into openlawlibrary:main Oct 28, 2024
16 checks passed
@alcarney alcarney deleted the server-methods branch October 28, 2024 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve asyncio event loop handling
2 participants