Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
quick fix kill command under windows (#3106)
Browse files Browse the repository at this point in the history
  • Loading branch information
J-shang authored Nov 27, 2020
1 parent 604f843 commit 62d5812
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
3 changes: 2 additions & 1 deletion nni/tools/nnictl/command_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def check_output_command(file_path, head=None, tail=None):
def kill_command(pid):
"""kill command"""
if sys.platform == 'win32':
psutil.Process(pid).terminate()
process = psutil.Process(pid=pid)
process.send_signal(signal.CTRL_BREAK_EVENT)
else:
cmds = ['kill', str(pid)]
call(cmds)
Expand Down
23 changes: 7 additions & 16 deletions ts/nni_manager/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,7 @@ mkDirP(getLogDir())
console.error(`Failed to create log dir: ${err.stack}`);
});

function getStopSignal(): any {
return 'SIGTERM';
}

function getCtrlCSignal(): any {
return 'SIGINT';
}

process.on(getCtrlCSignal(), async () => {
const log: Logger = getLogger();
log.info(`Get SIGINT signal!`);
});

process.on(getStopSignal(), async () => {
async function cleanUp(): Promise<void> {
const log: Logger = getLogger();
let hasError: boolean = false;
try {
Expand All @@ -206,7 +193,11 @@ process.on(getStopSignal(), async () => {
hasError = true;
log.error(`${err.stack}`);
} finally {
await log.close();
log.close();
process.exit(hasError ? 1 : 0);
}
});
}

process.on('SIGTERM', cleanUp);
process.on('SIGBREAK', cleanUp);
process.on('SIGINT', cleanUp);

0 comments on commit 62d5812

Please sign in to comment.