未验证 提交 f50a67eb 编写于 作者: K kuizhiqing 提交者: GitHub

fix os.setsid in windows (#34278)

上级 aff14962
...@@ -41,14 +41,16 @@ class LauncherInterface(object): ...@@ -41,14 +41,16 @@ class LauncherInterface(object):
def _terminate_procs(self): def _terminate_procs(self):
# try to terminate process by group, this happend in multiprocess senario in user process # try to terminate process by group, this happend in multiprocess senario in user process
for p in self.procs: if os.name != 'nt':
if p.proc.poll() is None: for p in self.procs:
os.killpg(os.getpgid(p.proc.pid), signal.SIGTERM) if p.proc.poll() is None:
if p.log_fn: os.killpg(os.getpgid(p.proc.pid), signal.SIGTERM)
p.log_fn.close() if p.log_fn:
logger.info("terminate process group gid:{}".format(p.proc.pid)) p.log_fn.close()
logger.info("terminate process group gid:{}".format(
p.proc.pid))
time.sleep(1) time.sleep(1)
for p in self.procs: for p in self.procs:
if p.proc.poll() is None: if p.proc.poll() is None:
p.proc.terminate() p.proc.terminate()
......
...@@ -517,6 +517,7 @@ def start_local_trainers(cluster, ...@@ -517,6 +517,7 @@ def start_local_trainers(cluster,
"details abouts PADDLE_TRAINER_ENDPOINTS can be found in {}/endpoints.log, and detail running logs maybe found in {}/workerlog.0". "details abouts PADDLE_TRAINER_ENDPOINTS can be found in {}/endpoints.log, and detail running logs maybe found in {}/workerlog.0".
format(log_dir, log_dir)) format(log_dir, log_dir))
fn = None fn = None
pre_fn = None if os.name == 'nt' else os.setsid
if log_dir is not None: if log_dir is not None:
os.system("mkdir -p {}".format(log_dir)) os.system("mkdir -p {}".format(log_dir))
if os.path.exists("%s/endpoints.log" % log_dir): if os.path.exists("%s/endpoints.log" % log_dir):
...@@ -526,13 +527,9 @@ def start_local_trainers(cluster, ...@@ -526,13 +527,9 @@ def start_local_trainers(cluster,
f.write("\n".join(cluster.trainers_endpoints())) f.write("\n".join(cluster.trainers_endpoints()))
fn = open("%s/workerlog.%d" % (log_dir, idx), "a") fn = open("%s/workerlog.%d" % (log_dir, idx), "a")
proc = subprocess.Popen( proc = subprocess.Popen(
cmd, cmd, env=current_env, stdout=fn, stderr=fn, preexec_fn=pre_fn)
env=current_env,
stdout=fn,
stderr=fn,
preexec_fn=os.setsid)
else: else:
proc = subprocess.Popen(cmd, env=current_env, preexec_fn=os.setsid) proc = subprocess.Popen(cmd, env=current_env, preexec_fn=pre_fn)
tp = TrainerProc() tp = TrainerProc()
tp.proc = proc tp.proc = proc
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册