From 880dc33847e140cc1b3d4cfb6adc1957ec884eba Mon Sep 17 00:00:00 2001 From: JackCaoG Date: Thu, 15 Apr 2021 23:36:18 +0000 Subject: [PATCH] Handle pgrep not installed --- torch_xla/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/torch_xla/__init__.py b/torch_xla/__init__.py index 71d47b0f848f..1b1b9d4e7df2 100644 --- a/torch_xla/__init__.py +++ b/torch_xla/__init__.py @@ -8,9 +8,11 @@ def server_is_alive(): - return len( - subprocess.Popen(['pgrep', '-f', XRT_SERVER_REGEX], - stdout=subprocess.PIPE).stdout.readline()) != 0 + # pgrep returns 0 when at least one running process matches the requested name. + # Otherwise, the exit code is 1. If pgrep is not availiable in the system, it + # will return an exit code 127. + return subprocess.getstatusoutput( + 'pgrep -f "{}"'.format(XRT_SERVER_REGEX))[0] == 0 def _setup_grpc():