diff --git a/parl/remote/scripts.py b/parl/remote/scripts.py index cbae1ccf2059c8cab6da934984db466e4f54ad88..e32b819d24bb9a598da8cd9278b83ac4fc3339ed 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 02815ea1a50387462b6072c47e4e1bc1efb130a8..868f5032c296af457e407a9b4555a0c36c75c895 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 c76a8dc87feca88bcd7e5f6b9335fcb4133dae4e..fb1f8dca5795c8fd4e1d65e722206672dee1a213 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 9b534eebbfa547853f7fefd2e8081be219d77d1f..e16e11d2345c80ff0c5f6f33a2296271c9a21c31 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)