From 0ebb57def325547cf6c5b9b519c693ea0daaf5aa Mon Sep 17 00:00:00 2001 From: Bo Zhou <2466956298@qq.com> Date: Wed, 19 Aug 2020 14:46:29 +0800 Subject: [PATCH] comiit (#392) --- parl/remote/scripts.py | 16 +++++++++++----- parl/remote/tests/log_server_test.py | 5 +---- parl/remote/tests/reset_job_test.py | 2 +- parl/remote/worker.py | 11 ++++++----- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/parl/remote/scripts.py b/parl/remote/scripts.py index cbae1cc..e32b819 100644 --- a/parl/remote/scripts.py +++ b/parl/remote/scripts.py @@ -171,22 +171,28 @@ def start_master(port, cpu_num, monitor_port, debug, log_server_port_range): # Redirect the output to DEVNULL to solve the warning log. _ = subprocess.Popen( - master_command, stdout=FNULL, stderr=subprocess.STDOUT) + master_command, stdout=FNULL, stderr=subprocess.STDOUT, close_fds=True) if cpu_num > 0: # Sleep 1s for master ready time.sleep(1) _ = subprocess.Popen( - worker_command, stdout=FNULL, stderr=subprocess.STDOUT) + worker_command, + stdout=FNULL, + stderr=subprocess.STDOUT, + close_fds=True) if _IS_WINDOWS: # TODO(@zenghsh3) redirecting stdout of monitor subprocess to FNULL will cause occasional failure tmp_file = tempfile.TemporaryFile() - _ = subprocess.Popen(monitor_command, stdout=tmp_file) + _ = subprocess.Popen(monitor_command, stdout=tmp_file, close_fds=True) tmp_file.close() else: _ = subprocess.Popen( - monitor_command, stdout=FNULL, stderr=subprocess.STDOUT) + monitor_command, + stdout=FNULL, + stderr=subprocess.STDOUT, + close_fds=True) FNULL.close() if cpu_num > 0: @@ -285,7 +291,7 @@ def start_worker(address, cpu_num, log_server_port_range): str(cpu_num), "--log_server_port", str(log_server_port) ] - p = subprocess.Popen(command) + p = subprocess.Popen(command, close_fds=True) if not is_log_server_started(get_ip_address(), log_server_port): click.echo("# Fail to start the log server.") diff --git a/parl/remote/tests/log_server_test.py b/parl/remote/tests/log_server_test.py index 02815ea..868f503 100644 --- a/parl/remote/tests/log_server_test.py +++ b/parl/remote/tests/log_server_test.py @@ -138,10 +138,7 @@ class TestLogServer(unittest.TestCase): else: FNULL = open(os.devnull, 'w') monitor_proc = subprocess.Popen( - command, - stdout=FNULL, - stderr=subprocess.STDOUT, - ) + command, stdout=FNULL, stderr=subprocess.STDOUT, close_fds=True) # Start worker cluster_addr = 'localhost:{}'.format(master_port) diff --git a/parl/remote/tests/reset_job_test.py b/parl/remote/tests/reset_job_test.py index c76a8dc..fb1f8dc 100644 --- a/parl/remote/tests/reset_job_test.py +++ b/parl/remote/tests/reset_job_test.py @@ -69,7 +69,7 @@ class TestJob(unittest.TestCase): file_path = __file__.replace('reset_job_test', 'simulate_client') command = [sys.executable, file_path] - proc = subprocess.Popen(command) + proc = subprocess.Popen(command, close_fds=True) for _ in range(6): if master.cpu_num == 0: break diff --git a/parl/remote/worker.py b/parl/remote/worker.py index 9b534ee..e16e11d 100644 --- a/parl/remote/worker.py +++ b/parl/remote/worker.py @@ -227,7 +227,11 @@ class Worker(object): # Redirect the output to DEVNULL FNULL = open(os.devnull, 'w') for _ in range(job_num): - subprocess.Popen(command, stdout=FNULL, stderr=subprocess.STDOUT) + subprocess.Popen( + command, + stdout=FNULL, + stderr=subprocess.STDOUT, + close_fds=True) FNULL.close() new_jobs = [] @@ -402,10 +406,7 @@ class Worker(object): else: FNULL = open(os.devnull, 'w') log_server_proc = subprocess.Popen( - command, - stdout=FNULL, - stderr=subprocess.STDOUT, - ) + command, stdout=FNULL, stderr=subprocess.STDOUT, close_fds=True) FNULL.close() log_server_address = "{}:{}".format(self.worker_ip, port) -- GitLab