Closed HeinischValentin closed 2 weeks ago
With Sphinx version 7.2.6 everything works fine
To be honest, I'm surprised this worked for you before.
The most common way for a language server like esbonio
to communicate with an editor is to print()
messages to stdout. Unfortunately, this means nothing else in the server process can use print()
as it will interfere with the communication between client and server - as you are seeing here.
The upcoming 1.0
release will move Sphinx out into a separate process which opens up the possibility to use a different communication mechanism. However the easiest solution for the time being is to work around this.
You could either use a logger from Sphinx's logging system
from sphinx.util.logging import getLogger
logger = getLogger("name")
def test_before_read_docs(a, b, c):
logger.info("test")
pass
def setup(app) -> dict[str, str | bool]:
app.connect("env-before-read-docs", test_before_read_docs)
return {"version": "0.1", "parallel_read_safe": False}
Or you could try printing to stderr instead
import sys
def test_before_read_docs(a, b, c):
print(test", file=sys.stderr)
pass
def setup(app) -> dict[str, str | bool]:
app.connect("env-before-read-docs", test_before_read_docs)
return {"version": "0.1", "parallel_read_safe": False}
Hope that helps!
Switching from using print
to the sphinx logger solves the issue, thank you very much!
I am also very confused why this problem only showed up since the latest Sphinx release.
Again, thanks for your help.
Expected behavior
I am working on a RST project inside VSCode, with the live preview setup. I have a minimal venv with Sphinx and esbonio installed. Inside my conf.py I connect some function to a Sphinx event and call the "print()" function inside the callback. With Sphinx version 7.2.6 everything works fine. I update to Sphinx 7.3.0 and expect the project to build.
Actual behavior
After updating to Sphinx version 7.3.0, esbonio is stuck building. When I try to restart the language server, it shuts down completely. When I remove the print statement from the callback function, esbonio works fine again. Print statements e.g. in the "setup" function of my conf.py do not break esbonio.
Log output
(Optional) Settings from conf.py