44
55import logging
66import threading
7- from typing import Any , Callable
7+ from typing import Callable
88
99import grpc
1010from ni .pythonpanel .v1 .python_panel_service_pb2 import ConnectRequest , DisconnectRequest
1111from ni .pythonpanel .v1 .python_panel_service_pb2_grpc import PythonPanelServiceStub
1212from ni_measurement_plugin_sdk_service .discovery import DiscoveryClient
1313from ni_measurement_plugin_sdk_service .grpc .channelpool import GrpcChannelPool
14+ from typing_extensions import ParamSpec , TypeVar
1415
1516_logger = logging .getLogger (__name__ )
1617
@@ -43,6 +44,16 @@ def __init__(
4344 if grpc_channel is not None :
4445 self ._stub = PythonPanelServiceStub (grpc_channel )
4546
47+ def connect (self , panel_id : str , panel_uri : str ) -> None :
48+ """Connect to the panel and open it."""
49+ connect_request = ConnectRequest (panel_id = panel_id , panel_uri = panel_uri )
50+ self ._invoke_with_retry (self ._get_stub ().Connect , connect_request )
51+
52+ def disconnect (self , panel_id : str ) -> None :
53+ """Disconnect from the panel (does not close the panel)."""
54+ disconnect_request = DisconnectRequest (panel_id = panel_id )
55+ self ._invoke_with_retry (self ._get_stub ().Disconnect , disconnect_request )
56+
4657 def _get_stub (self ) -> PythonPanelServiceStub :
4758 if self ._stub is None :
4859 with self ._initialization_lock :
@@ -60,7 +71,12 @@ def _get_stub(self) -> PythonPanelServiceStub:
6071 self ._stub = PythonPanelServiceStub (channel )
6172 return self ._stub
6273
63- def _invoke_with_retry (self , method : Callable [..., Any ], * args : Any , ** kwargs : Any ) -> Any :
74+ _T = TypeVar ("_T" )
75+ _P = ParamSpec ("_P" )
76+
77+ def _invoke_with_retry (
78+ self , method : Callable [_P , _T ], * args : _P .args , ** kwargs : _P .kwargs
79+ ) -> _T :
6480 """Invoke a gRPC method with retry logic."""
6581 try :
6682 return method (* args , ** kwargs )
@@ -69,13 +85,4 @@ def _invoke_with_retry(self, method: Callable[..., Any], *args: Any, **kwargs: A
6985 # if the service is unavailable, we can retry the connection
7086 self ._stub = None
7187 return method (* args , ** kwargs )
72-
73- def connect (self , panel_id : str , panel_uri : str ) -> None :
74- """Connect to the panel and open it."""
75- connect_request = ConnectRequest (panel_id = panel_id , panel_uri = panel_uri )
76- self ._invoke_with_retry (self ._get_stub ().Connect , connect_request )
77-
78- def disconnect (self , panel_id : str ) -> None :
79- """Disconnect from the panel (does not close the panel)."""
80- disconnect_request = DisconnectRequest (panel_id = panel_id )
81- self ._invoke_with_retry (self ._get_stub ().Disconnect , disconnect_request )
88+ raise
0 commit comments