Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix_abnormal_printing #7099

Merged
merged 8 commits into from
Dec 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions python/oneflow/distributed/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,23 @@ def main():
sig_names = {2: "SIGINT", 15: "SIGTERM"}
last_return_code = None

# set killing flag to make sure killing signal only executed once
kill_flag = True

def sigkill_handler(signum, frame):
nonlocal kill_flag
if not kill_flag:
return
for process in processes:
print(f"Killing subprocess {process.pid}")
try:
# Note: use os.kill or process.kill() may only kill current process
# use killpg will kill(use signal) this process and all sub-processes
# if orphan sub-processes still exist, use signal.SIGKILL instead.
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
except Exception:
pass
kill_flag = False
try:
# Note: use os.kill or process.kill() may only kill current process
# use killpg will kill(use signal) this process and all sub-processes
# if orphan sub-processes still exist, use signal.SIGKILL instead.
os.killpg(os.getpid(), signal.SIGTERM)
except Exception:
pass
if last_return_code is not None:
raise subprocess.CalledProcessError(
returncode=last_return_code, cmd=cmd
Expand Down