aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio_health_checking/grpc_health/v1/health.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/python/grpcio_health_checking/grpc_health/v1/health.py')
-rw-r--r--src/python/grpcio_health_checking/grpc_health/v1/health.py33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/python/grpcio_health_checking/grpc_health/v1/health.py b/src/python/grpcio_health_checking/grpc_health/v1/health.py
index 0df679b0e2..f0f11cf84b 100644
--- a/src/python/grpcio_health_checking/grpc_health/v1/health.py
+++ b/src/python/grpcio_health_checking/grpc_health/v1/health.py
@@ -26,7 +26,6 @@
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
"""Reference implementation for health checking in gRPC Python."""
import threading
@@ -37,23 +36,23 @@ from grpc_health.v1 import health_pb2
class HealthServicer(health_pb2.HealthServicer):
- """Servicer handling RPCs for service statuses."""
+ """Servicer handling RPCs for service statuses."""
- def __init__(self):
- self._server_status_lock = threading.Lock()
- self._server_status = {}
+ def __init__(self):
+ self._server_status_lock = threading.Lock()
+ self._server_status = {}
- def Check(self, request, context):
- with self._server_status_lock:
- status = self._server_status.get(request.service)
- if status is None:
- context.set_code(grpc.StatusCode.NOT_FOUND)
- return health_pb2.HealthCheckResponse()
- else:
- return health_pb2.HealthCheckResponse(status=status)
+ def Check(self, request, context):
+ with self._server_status_lock:
+ status = self._server_status.get(request.service)
+ if status is None:
+ context.set_code(grpc.StatusCode.NOT_FOUND)
+ return health_pb2.HealthCheckResponse()
+ else:
+ return health_pb2.HealthCheckResponse(status=status)
- def set(self, service, status):
- """Sets the status of a service.
+ def set(self, service, status):
+ """Sets the status of a service.
Args:
service: string, the name of the service.
@@ -61,5 +60,5 @@ class HealthServicer(health_pb2.HealthServicer):
status: HealthCheckResponse.status enum value indicating
the status of the service
"""
- with self._server_status_lock:
- self._server_status[service] = status
+ with self._server_status_lock:
+ self._server_status[service] = status