IO

class pygls.io_.StdinAsyncReader(stdin, executor=None)

Read from stdin asynchronously.

Parameters:
  • stdin (BinaryIO)

  • executor (ThreadPoolExecutor | None)

class pygls.io_.StdoutWriter(stdout)

Align a stdout stream with pygls’ writer interface.

Parameters:

stdout (BinaryIO)

class pygls.io_.WebSocketWriter(ws)

Align a websocket connection with pygls’ writer interface

Parameters:

ws (ServerConnection | ClientConnection)

pygls.io_.run(stop_event, reader, protocol, logger=None, error_handler=None)

Run a main message processing loop, synchronously

Parameters:
  • stop_event (threading.Event) – A threading.Event used to break the main loop

  • reader (Reader) – The reader to read messages from

  • protocol (JsonRPCProtocol) – The protocol instance that should handle the messages

  • logger (logging.Logger | None) – The logger instance to use

  • error_handler (Callable[[Exception, type[JsonRpcException]], Any] | None) – Function to call when an error is encountered.

async pygls.io_.run_async(stop_event, reader, protocol, logger=None, error_handler=None)

Run a main message processing loop, asynchronously

Parameters:
  • stop_event (threading.Event) – A threading.Event used to break the main loop

  • reader (AsyncReader) – The reader to read messages from

  • protocol (JsonRPCProtocol) – The protocol instance that should handle the messages

  • logger (logging.Logger | None) – The logger instance to use

  • error_handler (Callable[[Exception, type[JsonRpcException]], Any] | None)

async pygls.io_.run_websocket(websocket, stop_event, protocol, logger=None, error_handler=None)

Run the main message processing loop, over websockets.

Parameters:
  • stop_event (threading.Event) – A threading.Event used to break the main loop

  • websocket (ClientConnection | ServerConnection) – The websocket to read messages from

  • protocol (JsonRPCProtocol) – The protocol instance that should handle the messages

  • logger (logging.Logger | None) – The logger instance to use

  • error_handler (Callable[[Exception, type[JsonRpcException]], Any] | None) – Function to call when an error is encountered.