Service
pyvider.rpcplugin.protocol.service
¶
gRPC Service Implementations for Pyvider RPC Plugin.
This module provides the Python implementations for the standard gRPC services defined in the common go-plugin protocol: - GRPCBrokerService: For managing brokered subchannels. - GRPCStdioService: For streaming stdin/stdout/stderr. - GRPCControllerService: For controlling the plugin lifecycle (e.g., shutdown).
It also includes helper classes like SubchannelConnection and a registration
function to add these services to a gRPC server.
Classes¶
GRPCBrokerService
¶
Bases: GRPCBrokerServicer
Implementation of the gRPC Broker logic.
This matches the StartStream(...) signature in grpc_broker.proto, which
transmits a stream of ConnInfo messages in both directions.
In go-plugin, the plugin side uses:
'StartStream(stream ConnInfo) returns (stream ConnInfo)'
to set up a subchannel for callbacks or bridging. We'll do a simplified
version here.
Source code in pyvider/rpcplugin/protocol/service.py
Functions¶
StartStream
async
¶
StartStream(
request_iterator: AsyncIterator[ConnInfo],
context: ServicerContext[ConnInfo, ConnInfo],
) -> AsyncIterator[ConnInfo]
Handles the bidirectional stream for broker connections.
This gRPC method allows the client and server to exchange ConnInfo
messages to manage subchannels for additional services or callbacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_iterator
|
AsyncIterator[ConnInfo]
|
An async iterator yielding incoming |
required |
context
|
ServicerContext[ConnInfo, ConnInfo]
|
The gRPC request context. |
required |
Yields:
| Type | Description |
|---|---|
AsyncIterator[ConnInfo]
|
Outgoing |
Source code in pyvider/rpcplugin/protocol/service.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
GRPCControllerService
¶
Bases: GRPCControllerServicer
Implements the GRPCController service for plugin lifecycle management. Specifically, it handles the Shutdown RPC to gracefully terminate the plugin.
Initializes the GRPCControllerService.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shutdown_event
|
Event
|
An asyncio.Event to signal plugin shutdown. |
required |
stdio_service
|
GRPCStdioService
|
The GRPCStdioService instance to also shutdown. |
required |
Source code in pyvider/rpcplugin/protocol/service.py
Functions¶
Shutdown
async
¶
Handles the Shutdown RPC request from the client.
This method signals other plugin components to shut down gracefully and then initiates the process termination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Empty
|
The Empty request message (from grpc_controller.proto). |
required |
context
|
ServicerContext[Empty, Empty]
|
The gRPC request context. |
required |
Returns:
| Type | Description |
|---|---|
Empty
|
An Empty response message. |
Source code in pyvider/rpcplugin/protocol/service.py
GRPCStdioService
¶
Bases: GRPCStdioServicer
Implementation of plugin stdio streaming.
Source code in pyvider/rpcplugin/protocol/service.py
Functions¶
StreamStdio
async
¶
StreamStdio(
request: Empty,
context: ServicerContext[Empty, StdioData],
) -> AsyncIterator[StdioData]
Streams STDOUT/STDERR lines to the caller.
Source code in pyvider/rpcplugin/protocol/service.py
put_line
async
¶
Adds a line of data (stdout or stderr) to the message queue for streaming.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
bytes
|
The bytes data of the line. |
required |
is_stderr
|
bool
|
True if the line is from stderr, False for stdout. |
False
|
Source code in pyvider/rpcplugin/protocol/service.py
SubchannelConnection
¶
Represents a brokered subchannel for plugin-to-plugin communication.
In the go-plugin architecture, subchannels allow plugins to establish secondary communication channels for callbacks, additional services, or plugin-to-plugin communication. Each subchannel has a unique ID and network address.
Attributes:
| Name | Type | Description |
|---|---|---|
conn_id |
int
|
Unique identifier for this subchannel connection. |
address |
str
|
Network address for the subchannel (format depends on transport). |
is_open |
bool
|
Whether the subchannel is currently open and available. |
Example
Functions¶
close
async
¶
Close the subchannel and release resources.
This method closes the subchannel connection and marks it as unavailable. Resources associated with the subchannel are released.
Side Effects
Sets is_open to False after closing.
Source code in pyvider/rpcplugin/protocol/service.py
open
async
¶
Open the subchannel for communication.
This method establishes the subchannel connection and marks it as available for use. In a real implementation, this would involve network setup or IPC channel creation.
Side Effects
Sets is_open to True after successful opening.
Source code in pyvider/rpcplugin/protocol/service.py
Functions¶
register_protocol_service
¶
Registers all standard gRPC services for the plugin.