From acc311dd3e15135ca35f69b0183e5b0f9f4beadf Mon Sep 17 00:00:00 2001 From: demianzhang <15094695770@163.com> Date: Sun, 28 Apr 2019 14:39:37 +0800 Subject: [PATCH] Update check_ready_to_run in windows local mode (#1025) * Update mnist-hyperband.test.yml * Fix system node * Fix pgrep in windows --- tools/nni_gpu_tool/gpu_metrics_collector.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/nni_gpu_tool/gpu_metrics_collector.py b/tools/nni_gpu_tool/gpu_metrics_collector.py index 37a76dacd2..56095a0362 100644 --- a/tools/nni_gpu_tool/gpu_metrics_collector.py +++ b/tools/nni_gpu_tool/gpu_metrics_collector.py @@ -25,15 +25,20 @@ from xml.dom import minidom def check_ready_to_run(): - #TODO check process in windows if sys.platform == 'win32': - return True - pgrep_output =subprocess.check_output('pgrep -fx \'python3 -m nni_gpu_tool.gpu_metrics_collector\'', shell=True) - pidList = [] - for pid in pgrep_output.splitlines(): - pidList.append(int(pid)) - pidList.remove(os.getpid()) - return len(pidList) == 0 + pgrep_output = subprocess.check_output('wmic process where "CommandLine like \'%nni_gpu_tool.gpu_metrics_collector%\' and name like \'%python%\'" get processId') + pidList = pgrep_output.decode("utf-8").strip().split() + pidList.pop(0) # remove the key word 'ProcessId' + pidList = list(map(int, pidList)) + pidList.remove(os.getpid()) + return len(pidList) == 0 + else: + pgrep_output =subprocess.check_output('pgrep -fx \'python3 -m nni_gpu_tool.gpu_metrics_collector\'', shell=True) + pidList = [] + for pid in pgrep_output.splitlines(): + pidList.append(int(pid)) + pidList.remove(os.getpid()) + return len(pidList) == 0 def main(argv): metrics_output_dir = os.environ['METRIC_OUTPUT_DIR']