From a1b6c78b5daa781a64965914aae28cd536b16bd1 Mon Sep 17 00:00:00 2001 From: JackCaoG Date: Fri, 16 Apr 2021 00:15:15 +0000 Subject: [PATCH] cherry pick f41a53458d12b19027f02e5ec34f51d187a63368 --- 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 e56664c34e95..dee9ed93be26 100644 --- a/torch_xla/__init__.py +++ b/torch_xla/__init__.py @@ -13,9 +13,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 _maybe_select_tpu_version():