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

fix os.setsid in windows (#34278)

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